- changed status to on hold
False positive on MissingNotificationCenterDetachment
Issue #26
on hold
If an objects observes several notifications, I often clean up with a for
:
- (void)dealloc {
for (NSString *name in @[kMBLocationManagerNotificationAuthorizationChangedName,
kMBLocationManagerNotificationLocationUpdatedName,
COIQRCodeScanned,
COIItemRedeemed,
COIUserLoggedInNotification]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:name object:nil];
}
}
Faux Pas doesn't seem to understand it and I get a false positive.
Comments (2)
-
repo owner -
The reason is that you shouldn't use
-[NSNotificationCenter removeObserver:]
on any place expectdealloc
. I don't use it even ondealloc
to avoid other (less experienced) people to copy it and paste it some place where it'd be a problem (e.g. http://subjective-objective-c.blogspot.com.br/2011/04/avoid-nsnotification-removeobserver.html). - Log in to comment
Thanks for reporting this. Is there any reason why you cannot use
-[NSNotificationCenter removeObserver:]
instead? It's much simpler and less error prone, and would sidestep this false positive.