R – How to access fetched property in Objective-C 2.0 using Core data

core-dataiphoneobjective c

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.

Best Answer

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]);