2
votes

I'm new to IPhone development and I'm currently trying my hand at Core Data. I have a couple of entities that I've defined in my model. In one entity I have a fetched property. When I generate the Objective-C source files from my model, my entity that I defined with the fetched property does not have a property defined for the fetched property. Why? How do I access the fetched property?

More details in response to Tim:

  • I have an entity named Library and another entity named Book.
  • Library has a one to many relationship to Book (Book also has an inverse relationship).
  • Book has a BOOL property called isCheckedOut.
  • I defined a fetched property on Library called fetchAllCheckedOutBooks. The destination entity is Book and the predicate is isCheckedOut == 1.
3
It would help if we could know the destination entity and predicate you have set for the fetched property. Also, I assume you're having Xcode generate the source files?Tim

3 Answers

6
votes

Have you tried using valueForKey: and passing in the name of your fetched property? That's how I would expect it to work. I would also expect that it would return an NSSet object, but that's easily verified by doing this:

id results = [myManagedObject valueForKey:@"fetchedPropertyName"];
NSLog(@"%@", [results className]);
1
votes

Yeah, this is annoying....

Fetched properties are returned as an NSArray, so you just have to add it yourself:

//.h @property (nonatomic, retain) NSArray *fetchedPropertyName;

//.m @dynamic fetchedPropertyName;

0
votes

yeah, really odd that Xcode doesn't include this when it generates the NSManagedObject subclass like it does for regular attributes and relationships