On 11 Sep 2013, at 13:55, Graham Cox <[email protected]> wrote:
> > On 11/09/2013, at 1:35 PM, Dave <[email protected]> wrote: > >> Is there any problem with having all notifications handled by one object >> that doesn't go away, > > Well, [NSNotificationCenter defaultCenter] is that object… Yes, but it doesn't remember the last value of a notification, which is what I would like. >> and have this ship the notificationa off to the correct object as long as it >> is still alive? The way this App is designed is I can tell if the object is >> allocated or not and if it is allocated, then I want it to receive >> notifications > > > The correct way to deal with this is to remove yourself as a receiver of > notifications when you are deallocated. The documentation, in its roundabout > way, does state this. > > - (void) dealloc > { > [[NSNotificationCenter defaultCenter] removeObserver:self]; > ... > > [super dealloc]; > } > > > This pattern works without resorting to any odd hacks to avoid notifying a > dead object. Since that removes all possible notifications for 'self' it's a > good habit to add this automatically as soon as you add any notificaition > observations to your code. Yes, I am removing myself as a receiver, but ideally I want to receive these notification even if the object is dead. By this I mean, I want the last known value of the notification restored when the Object in question starts up again. At present I have to save this somewhere ugly and restore it from somewhere ugly. I just thought it would be nice to be able to just make a call something like: -(void) reissueLastNotificationName:@"Note1" forClass:self Rather than save it somewhere ugly 26 more times! I could maybe subclass NSNotificationCenter? All the Best Dave _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
