Re: Core Data, fetched property question
Re: Core Data, fetched property question
- Subject: Re: Core Data, fetched property question
- From: Bob Sanders <email@hidden>
- Date: Fri, 9 Sep 2005 18:54:44 -0500
I found the problem: a fetched property returns an array, not a
single object. I can easily test for my condition by checking the
length of the array returned by valueForKey.
On Sep 9, 2005, at 5:39 PM, Bob Sanders wrote:
This seems like it should be totally easy, but I'm stumped.
First, the question: should valueForKey on a fetched property
return nil if the predicate doesn't match any objects?
I have a model that defines a Week object with a to-many
relationship to one or more Day objects. A Day has an integer
"dayOfWeek" (1-7) and a relationship back to the parent Week object.
I'm just trying to learn CD at this point, so I created a fetched
property on the Week object called "sunday", with destination of
"Day" and a predicate of dayOfWeek == 1 (I also added AND week ==
"SELF") with a later test. I also created a monday fetched property
with a dayOfWeek==2.
So far so good, until I tried to get the object:
// grab the selected object from the arraycontroller
NSManagedObject *selectedWeek = [[planWeekArray selectedObjects]
objectAtIndex:0];
// see if a sunday object is defined
NSManagedObject *sunday = [selectedWeek valueForKey:@"sunday"];
if( sunday == nil ){
NSLog(@"SUNDAY NIL: %@", sunday);
}else{
NSLog(@"SUNDAY GOOD: %@", [sunday valueForKey:@"dayOfWeek"]);
}
I have exactly one day object defined with dayOfWeek=1, and this
call correctly returns that object.
However, when I change to valueForKey:@"monday", I get a non-nil
value back, so my console output looks like this:
SUNDAY GOOD: ()
I don't know where those () come from, or how I can test the return
value of the fetched property.
Any ideas?
Thanks in advance,
Bob
_______________________________________________
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