Re: Knowing when a NSArrayController is ready
Re: Knowing when a NSArrayController is ready
- Subject: Re: Knowing when a NSArrayController is ready
- From: Dave Fernandes <email@hidden>
- Date: Sat, 24 Jan 2009 13:11:57 -0500
It looks like you can set to prepare content AND call fetchWithRequest:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CoreData/
Articles/cdBindings.html
"If the "automatically prepares content" flag (see, for example,
setAutomaticallyPreparesContent:) is set for a controller, the
controller's initial content is fetched from its managed object
context using the controller's current fetch predicate. It is
important to note that the controller's fetch is executed as a
delayed operation performed after its managed object context is set
(by nib loading)—this therefore happens after awakeFromNib and
windowControllerDidLoadNib:. This can create a problem if you want to
perform an operation with the contents of an object controller in
either of these methods, since the controller's content is nil. You
can work around this by executing the fetch "manually" with
fetchWithRequest:merge:error:. You pass nil as the fetch request
argument to use the default request, as illustrated in the following
code fragment."
On Jan 24, 2009, at 12:59 PM, 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];
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:
40utoronto.ca
This email sent to email@hidden
_______________________________________________
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