• 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: KVO can be unsafe in -init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO can be unsafe in -init?


  • Subject: Re: KVO can be unsafe in -init?
  • From: Roland King <email@hidden>
  • Date: Thu, 10 Sep 2009 00:04:00 +0800



What about writing a method, -finishSetup, and invoke it with a delay like below? I use this pattern a lot with loading views. It seems like it would work so that you add observation when your object is ready.


Marc

[self performSelectorOnMainThread:@selector(finishSetup) withObject:nil waitUntilDone:NO];

- (void)finishSetup;
{
[[XYZManager sharedManager] addObserver:self forKeyPath:@"allObjects" options:NSKeyValueObservingOptionInitial context:NULL];
}



I can see why you'd suggest this and it may well work but .. I have to say .. it's a little ugh. If that sorts out the problem it would mean that even if you are on the very last line of your init method, before you return self, with no subclasses or other issues, your object is still not 'whole' enough to receive messages, messages in this case which are defined on your base class, NSObject, whos init method was finished long ago. I would like to think that isn't the case, certainly no documentation I've ever read has indicated that's the case.


Definitely you have to be very thoughtful about what you put in an initializer which references self, and where you put it, more-so if you have subclasses, but my feeling is you should be able to add an observer on another class and get a callback and that callback should work if you've set up the rest of your object beforehand correctly, or at least the bits of it that callback needs.


_______________________________________________

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


References: 
 >Re: KVO can be unsafe in -init? (From: Marc Respass <email@hidden>)

  • Prev by Date: Re: Scripting Bridge and Powerpoint, how to make new slide?
  • Next by Date: Re: Does Mac OS X support interior pointers?
  • Previous by thread: Re: KVO can be unsafe in -init?
  • Next by thread: NSOutlineView with multiple Core Data entities
  • Index(es):
    • Date
    • Thread