• 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: Graham Cox <email@hidden>
  • Date: Wed, 11 Sep 2013 14:55:56 +0200

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


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


--Graham


_______________________________________________

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>
References: 
 >Crashing Problem calling postNotificationName (From: Dave <email@hidden>)
 >Re: Crashing Problem calling postNotificationName (From: Dave <email@hidden>)

  • Prev by Date: Re: Crashing Problem calling postNotificationName
  • Next by Date: Re: Crashing Problem calling postNotificationName
  • Previous by thread: Re: Crashing Problem calling postNotificationName
  • Next by thread: Re: Crashing Problem calling postNotificationName
  • Index(es):
    • Date
    • Thread