Re: Knowing when a NSArrayController is ready
Re: Knowing when a NSArrayController is ready
- Subject: Re: Knowing when a NSArrayController is ready
- From: "email@hidden" <email@hidden>
- Date: Sat, 24 Jan 2009 18:17:05 +0000
On 24 Jan 2009, at 17:59, Matt Neuburg wrote:
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];
I have been utilising the NSPersistentDocument sample code with
bindings and prepareContent enabled.
Going back to my code I see that I was actually observing the content
of an NSObjectController not the arrangedObjects of an
NSArrayController.
Apologies for that.
This observation seems to work okay, but there may well be issues as
you suggest observing arrangedObjects.
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.
I am also having horrible performance problems.
A data set of 1500 items with a total on disk size of 1.8MB is taking
more than 30 secs to load.
Maybe NSArrayController -fetchWithRequest will improve things.
--
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>
Jonathan Mitchell
Central Conscious Unit
http://www.mugginsoft.com
_______________________________________________
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