Re: KVO can be unsafe in -init?
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