Question

I having trouble using boolean properties with overridden getter method names. For example, in my NSManageObject subclass's header I have:

@property (nonatomic, retain, getter=isActive) NSNumber * active;

in the implementation file I have:

@dynamic active;

Xcode recognizes the "isActive" method and autocompletes it for me while I'm typing and the code compiles without errors. However, this code:

MyObject *newObject = (MyObject *)[NSEntityDescription insertNewObjectForEntityForName:@"MyObject" inManagedObjectContext:[self context]];
NSNumber * tagActive = [newObject isActive];

Fails with the classic:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyObject isActive]: unrecognized selector sent to instance 0xb67e760'

I have tested removing the custom getter and simply accessing the active property with [myObject active] which does work. Do NSManagedObject properties not support this or am I doing something wrong?

Was it helpful?

Solution

@dynamic doesn't actually generate setters and getters for a method, it just tells the compiler that something will. So I think NSManagedObject only generates standard named setters and getters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top