Re: fetch request with compound predicate doesn't sort properly
Re: fetch request with compound predicate doesn't sort properly
- Subject: Re: fetch request with compound predicate doesn't sort properly
- From: Ken Victor <email@hidden>
- Date: Thu, 16 Mar 2006 07:14:01 -0800
At 8:18 PM -0800 3/15/06, Greg Herlihy wrote:
The object model always returns the same NSFetchRequest object for a
template name (unless the request uses substitution variables). So
it would make sense that any sort descriptors used for previous
requests would "stick" with the request - it's the same object after
all.
this makes sense. thanx.
It's also less clear why making a copy of the NSFetchRequest object
would clear its sort descriptors - I would expect them to be copied
as well. Instead of copying the request, I would have the program
set the sort descriptors to an empty array for any request whose
results do not need to be sorted. At any rate, I think that the
state of the NSFetchRequest object returned by the object model
(particularly the state of its sort descriptors) is the most likely
cause of the problem (which also explains why requests created
programmatically sort correctly, because the same request object is
not being re-used for each set of objects fetched.)
At this point, it's not clear what in particular would be wrong with
the state of the NSFetchRequest object - or how it got into that
state. Nonetheless, that seems that most promising theory to me.
i'm not so sure this makes sense to me. note that i had the same
problem whether or not i copy the the result of getting the template
from the model. also note that i copy the fetch request BEFORE adding
any sort descriptors, so the object from the model never has any sort
descriptors set. (i have verified this by examining the fetch
request(s) in the debugger.) if you recall, i only have a problem
when attempting to use a "sorted fetch" iff the MOC has not been
saved; once the MOC has been saved once, everything works as expected.
this does raise a question i've been meaning to ask tho: is it
possible to set sort descriptors using xcode's core data object
modelling capability?
thanx,
ken
Greg
On 3/14/06 4:00 PM, "Ken Victor" <email@hidden> wrote:
At 3:51 PM -0800 3/14/06, Greg Herlihy wrote:
Is there a reason for making a copy of the NSFetchRequest? And have
you tested without making this copy:
NSFetchRequest* request = [objectModel fetchRequestTemplateForName: fn];
the same problem exists whether or not i make the copy. i make the
copy because i use the same fetch request with different sort
descriptors at various parts of my app. i discovered empiracally
that setting the sort descriptors on a request retrieved from the
model "stuck" with the request the next time i retreived it from the
model. i didn't quite understand why this was so, but figured the
easiest solution was simply to use a copy and then "attach" the
appropriate sort descriptors as needed.
ken
Greg
On 3/14/06 3:30 PM, "Ken Victor" <email@hidden> wrote:
> NSFetchRequest* request = [[[objectModel
fetchRequestTemplateForName: fn] copy] autorelease];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden