On Jun 5, 2014, at 00:26 , Lee Ann Rucker <[email protected]> wrote:

> If you're doing something like this:
> 
> - (void)setFoo: (Foo *)aFoo
> {
>  [foo removeObserver:self forKeyPath:@"whatever"...];
>  foo = aFoo;
>  [foo addObserver:self forKeyPath:@"whatever"...;
> }
> 
> we used that pattern for a while but were constantly getting bit by observers 
> on objects being dealloced or KVO firing and triggering unwanted side effects 
> if we called setFoo: in dealloc. So we did a complete switch over to doing
> 
> [self addObserver:self forKeyPath:@"foo.whatever"...
> 
> in init, and removeObserver in dealloc, because you can remove an observer on 
> yourself in dealloc without the "observers still registered" warning.
> 
> Since it's on self, you can set it before foo exists, and setFoo: triggers 
> it. Plus we could use synthesized setters.

I collect the removeObserver calls into an "ignoreFoo" method, and similarly 
the addObserver in an "observeFoo" method. Then in -dealloc I call -ignoreFoo. 
I've never run into the (annoying) registration mismatch errors.

Your suggestion is a good one, but I don't think it solves the problem I have 
of -setFoo: being called before -viewDidLoad (before the IBOutlets are non-nil).

-- 
Rick




_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to