Re: Detecting when fetch: finishes
Re: Detecting when fetch: finishes
- Subject: Re: Detecting when fetch: finishes
- From: Keary Suska <email@hidden>
- Date: Wed, 3 Jun 2009 19:21:48 -0600
On Jun 3, 2009, at 6:19 PM, Ulai Beekam wrote:
What do you mean do the fetch myself? Do you mean I should not use
an NSArrayController? That would sound overkill as NSArrayController
plus its fetch predicate gives me a lot of functionality for free,
e.g. updating dynamically when underlying objects are added/removed.
Can you elaborate?
No, you can use the array controller, just have an object that
provides the controllers content instead of having the array
controller fetch it itself. Bind the NSArrayController's contentArray
to the array managed by the object, and turn off prepares content. You
will still get all the free functionality as long as you always add/
delete through the array controller or through KVO-compliant means. If
you need to watch for insertions/deletions that are performed outside
of the array controller and it is not practical to route them through
the object managing the content, you can have it simply observe
the"ObjectsDidChange" notification. See the docs for how to access the
changed objects. I think that is all that the controllers do anyway.
I suppose you could call -performSelector:afterDelay: for your
followup function, playing with delay values until you find one that
seems to reliably occur after the fetch. I don't know whether this
approach is deterministic, or how you would handle an error situation.
Seems altogether better to me to just handle fetching yourself.
I wonder if you can make an NSArrayController subclass, override -
fetchWithRequest:merge:error: to just call super, and after the call
(which should be synchronous), call your special post-processing
method. Just a stab in the dark, but might work.
----------------------------------------
From: email@hidden
To: email@hidden
Date: Wed, 3 Jun 2009 17:31:32 -0600
Subject: Re: Detecting when fetch: finishes
On Jun 3, 2009, at 5:12 PM, Ulai Beekam wrote:
I have an NSArrayController that, at the request of the user, can be
given a new fetch predicate. To do that I use the setFetchPredicate:
method. How can I detect when this predicate has been applied and
the appropriate fetching is done? I have not come across any
delegate method for it.
I suspect that this is made tricky because of the following quote
from the docs under the fetch: method of NSObjectController (which
by the way is a superclass of NSArrayController):
"Beginning with Mac OS X v10.4 the result of this method is deferred
until the next iteration of the runloop so that the error
presentation mechanism can provide feedback as a sheet."
So the problem is that it finishes somewhere in the next runloop
iteration, making it harder to do some custom things after it
finishes.
There isn't any way that I know that is more work than it is worth.
Better to do the fetch yourself.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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