> On 2015 Jan 25, at 22:03, Kyle Sluder <k...@ksluder.com> wrote:
> 
> On Sun, Jan 25, 2015, at 05:16 PM, Jerry Krinock wrote:

>> • When an observer is being torn down you can remove all observers with
>> one line of code,
>>     [NSNotificationCenter removeObserver:self].

> This is a dangerous API. If your superclass has registered for any
> observations, you will unregister before your superclass hears about it.

I see what you mean, that if the superclass needed for some reason to receive 
some notification at the bitter end of an object’s life, that line of code 
would break it.  I’m trying to imagine such a requirement.  Maybe to push 
changes to a data model in a view that was editing?  But we have various 
-endEditing methods for that.

On the other hand, I’ve seen many crashes occur from not removing observers 
early enough.  In general, as soon as it’s confirmed that an object is going 
away, the very first thing I do is to remove all of its observances.  It has 
worked for me, but from now on I’ll think about what you said.

> You can use the magic of C's sizeof keyword to avoid repeating yourself
> for each observed keypath:

And C arrays.  Very cool, Kyle.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to