• 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: Marc Respass <email@hidden>
  • Date: Wed, 09 Sep 2009 09:29:46 -0400

We have a singleton with an -init that looks something like this:
- (id)init
{

if ((self = [super init]))
{

_foo = [[NSMutableDictionary alloc] init];
_bar = [[NSMutableDictionary alloc] init];

[[XYZManager sharedManager] addObserver:self forKeyPath:@"allObjects"
options:NSKeyValueObservingOptionInitial context:NULL];

}
return self;

}

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];
}


_______________________________________________

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: KVO can be unsafe in -init?
      • From: Roland King <email@hidden>
  • Prev by Date: Snow Leopard turns CMYK jpegs green
  • Next by Date: RE: NSURLDownload delegate methods seperate thread
  • Previous by thread: Re: KVO can be unsafe in -init?
  • Next by thread: Re: KVO can be unsafe in -init?
  • Index(es):
    • Date
    • Thread