Re: Knowing when a NSArrayController is ready
Re: Knowing when a NSArrayController is ready
- Subject: Re: Knowing when a NSArrayController is ready
- From: Matt Neuburg <email@hidden>
- Date: Sat, 24 Jan 2009 09:59:08 -0800
- Thread-topic: Knowing when a NSArrayController is ready
On Sat, 24 Jan 2009 09:07:59 +0000, "email@hidden"
<email@hidden> said:
>
>On 24 Jan 2009, at 02:43, David LeBer wrote:
>
>> This may be a stupid question, but I've had reason to wonder a
>> number of times.
>>
>> If I have an NSArrayController in a nib, bound to a MOC, configured
>> with an Entity name and set to prepare content:
>>
>> Is there a way to be notified when it has finished loading and
>> arranging it's objects?
>>
>Hi David
>
>Adding an observer on the controller's arrangedObjects property should
>do the trick.
>
>[arrayController addObserver:self forKeyPath:@"arrangedObjects"
>options:0 context:(void *)&ControllerContentContext];
>
>In a persistent document based app, for example, the controller's MO
>content is not yet available in - (void)windowControllerDidLoadNib:
>(NSWindowController *)windowController.
>Adding the observer means you can set up any dependent code when the
>binding/core data machinery has finished doing its thing.
Is that really true? I'm not saying you're wrong; I'm really asking. When I
posed the same question a couple of years back, I was told that the solution
is, do *not* "set to prepare content"; instead, load the data yourself by
calling fetchWithRequest:
[arrayController fetchWithRequest:nil merge:NO error:&error];
When that call returns, the data is ready. I just now tried adding
addObserver: to the mix, just as an experiment, and logging reveals that I
get two corresponding calls to observeValueForKeyPath:, *before*
fetchWithRequest: has returned. The two calls are quite far apart (half a
second or so). Well, I sure wouldn't want to run my "dependent code" half a
second too early. So I'm not convinced that this approach is entirely safe,
at least not without some further modification... m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
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