• 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: viewDidLoad and KVO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: viewDidLoad and KVO


  • Subject: Re: viewDidLoad and KVO
  • From: Alejandro Visiedo García <email@hidden>
  • Date: Thu, 05 Jun 2014 15:26:02 +0200

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!

> El 05/06/2014, a las 09:30, Rick Mann <email@hidden> escribió:
>
>
>> On Jun 5, 2014, at 00:26 , Lee Ann Rucker <email@hidden> 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@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: viewDidLoad and KVO
      • From: Rick Mann <email@hidden>
References: 
 >viewDidLoad and KVO (From: Rick Mann <email@hidden>)
 >Re: viewDidLoad and KVO (From: Lee Ann Rucker <email@hidden>)
 >Re: viewDidLoad and KVO (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Drawing custom contiguous selection highlight in view-based NSOutlineView
  • Next by Date: Re: viewDidLoad and KVO
  • Previous by thread: Re: viewDidLoad and KVO
  • Next by thread: Re: viewDidLoad and KVO
  • Index(es):
    • Date
    • Thread