Re: Crashing Problem calling postNotificationName
Re: Crashing Problem calling postNotificationName
- Subject: Re: Crashing Problem calling postNotificationName
- From: Dave <email@hidden>
- Date: Thu, 12 Sep 2013 20:44:05 +0100
On 12 Sep 2013, at 20:24, Etienne Samson <email@hidden> wrote:
>
> That's not true : you won't get notifications sent by the Cocoa framework, because it will use `[NSNotificationCenter defaultCenter]` and you have (obviously) no way to change the sender.
>
> I feel like I'm playing the devil's advocate here Dave, but you'd have a more fool-proof solution with the cache solution I described. You won't have the problem pointed out by Kyle that you end up with 2 notification centers (and can't cache Cocoa's own notifications unless you have the subclass register with the default center). Maybe you'll have 26-or-more registerObserver: calls to change (to add the "then check cached notification" call), but in the end run, you've just removed a dependency on a subclass whose superclass you know nothing about. Again (and I speak from experience), better be safe than sorry if NSNotificationCenter semantics change and your app stop working.
The way this was setup before I added any of this was that the whole app calls a method called getNotificationCenter that returns [NSNotificationCenter defaultCenter], that's the only notification center the App knows about.
All I have done it make a subclass of NSNotificationCenter, called LTWCachedNotificationCenter and I return that instead of [NSNotificationCenter defaultCenter] in the getNotificationCenter method. The rest of the app stays the same, apart from the places that call the new methods.
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden