views:

28

answers:

3

I've got the following bit of code in one of my methods:

...
NSNumber *selectedRecordID = [NSNumber numberWithInt:ABRecordGetRecordID(person)];
for (NSManagedObject *managedObject in fetchedResultsController.fetchedObjects) {
    if (selectedRecordID == managedObject.contactID) { // this line generates a compiler error
     // do some stuff
     }

The indicated line generates the compiler error "Request for 'contactID' in something not a structure or a union." However, 'contactID' is an attribute of the entities retrieved by the fetched results controller, and is present in the @property declarations generated by Core Data.

What am I missing here? Thanks in advance for any help you can give.

A: 

But 'contactID' is not a property of the base NSManagedObject class, it's a property of your own entity class. For the property to be recognized by the compiler, you need to declare the fetched object using the appropriate type, for example:

for (MyEntity *managedObject in fetchedResultsController.fetchedObjects) {
if (selectedRecordID == managedObject.contactID) { 
 }
David Gelhar
That did it; thanks for the help.
Andy
A: 

You can also use KVC and avoid subclassing via:

[managedObject valueForKey:@"contactID"];
Marcus S. Zarra
A: 

You can also use KVC and avoid subclassing via:

[managedObject valueForKey:@"contactID"];
Marcus S. Zarra