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 18:00:34 +0100
On 12 Sep 2013, at 09:54, Graham Cox <email@hidden> wrote:
>
> On 11/09/2013, at 5:33 PM, Etienne Samson <email@hidden> wrote:
>
>> I think the best way for what you're trying to do is to subclass NSNotificationCenter (or at least provide your own framework-wide singleton that quacks like it), wrap -postNotification: with some dictionary-munging code that keeps tracks of the last notification send by notification name, and have -addObserver:… (you'll have to find the one that actually is the designated call, the one all the others expect) check that cache and issue a -postNotification: call for that object only (you don't want to notify all old objects, only the one that just registered).
>
>
> I'd disagree with this - subclassing something like NSNotificationCenter is a sledgehammer to crack a nut, and don't forget about the potential side effects where it is used for lots of other unrelated notifications.
>
> Why not just have a class method on the sender of the notification that stores the most recent data sent by an instance of that class? Then when a new instance of the notification receiver is inited, it can grab the latest data from the class method to set itself up? No hacks required.
I see your point but there were 27 cases like this and I didn't want to add all that code. The only impact on NSNotificationCenter to the rest of the App is that
- (void)postNotificationName:(NSString*) theName object:(id) theObject userInfo:(NSDictionary*) theUserInfoDictionary;
Which just stores the notification name and the User Info dictionary in a private dictionary.
Then just the places that need it call:
+(void) repostNotiticationName:(NSString*) theName;
+(NSDictionary*) getRememberedNotiticationName:(NSString*) theName;
Thinking about it again now, it might have been better to add a
- (void)postAndRememberNotificationName:(NSString*) theName object:(id) theObject userInfo:(NSDictionary*) theUserInfoDictionary;
Maybe I will revisit at some point.
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