rspec/rules/S4183/swift/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

52 lines
989 B
Plaintext

== Why is this an issue?
Classes can register themselves to receive notifications using ``++NotificationCenter.add++``. Having done so, it seems suspicious that a class would opt to stop receiving notifications before de-initialization. For that reason, this rule raises an issue when ``++NotificationCenter.default.removeObserver(self)++`` is called anywhere but in ``++deinit++``
=== Noncompliant code example
[source,swift]
----
class MyClass {
func doTheThing() {
//...
NotificationCenter.default.removeObserver(self) // Noncompliant
}
}
----
=== Compliant solution
[source,swift]
----
class MyClass {
func doTheThing() {
//...
}
func deinit() {
NotificationCenter.default.removeObserver(self)
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this call to (a|the) "deinit" method.
=== Highlighting
``++removeObserver(self)++``
endif::env-github,rspecator-view[]