On Jun 5, 2014, at 06:26 , Alejandro Visiedo García <[email protected]> wrote:
> Why don't you use viewWillAppear and viewDidDisappear, to register and > unregister observers to your foo property object? > > If you don't use ARC, be carefull to unregister on dealloc too! That, combined with observing on self.foo, might work, except that the appear/disappear calls aren't guaranteed to be balanced. > >> El 05/06/2014, a las 09:30, Rick Mann <[email protected]> escribió: >> >> >>> 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/alejandro.visiedo%40gmail.com >> >> This email sent to [email protected] -- 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]
