• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crashing Problem calling postNotificationName
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crashing Problem calling postNotificationName


  • Subject: Re: Crashing Problem calling postNotificationName
  • From: Etienne Samson <email@hidden>
  • Date: Wed, 11 Sep 2013 17:33:14 +0200

Hi !

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).

HTH.

Regards,
Etienne Samson
--
Cordialement,
Etienne Samson
--
email@hidden

Le 11 sept. 2013 à 15:13, Dave <email@hidden> a écrit :

>
> On 11 Sep 2013, at 13:55, Graham Cox <email@hidden> wrote:
>
>>
>> On 11/09/2013, at 1:35 PM, Dave <email@hidden> 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@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


_______________________________________________

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


  • Follow-Ups:
    • Re: Crashing Problem calling postNotificationName
      • From: Dave <email@hidden>
    • Re: Crashing Problem calling postNotificationName
      • From: Graham Cox <email@hidden>
References: 
 >Crashing Problem calling postNotificationName (From: Dave <email@hidden>)
 >Re: Crashing Problem calling postNotificationName (From: Dave <email@hidden>)
 >Re: Crashing Problem calling postNotificationName (From: Graham Cox <email@hidden>)
 >Re: Crashing Problem calling postNotificationName (From: Dave <email@hidden>)

  • Prev by Date: Re: 64-bit iOS
  • Next by Date: Re: ARC vs Manual Reference Counting
  • Previous by thread: Re: Crashing Problem calling postNotificationName
  • Next by thread: Re: Crashing Problem calling postNotificationName
  • Index(es):
    • Date
    • Thread