Tony Eichelberger Tony Eichelberger - 3 months ago 6
Objective-C Question

How can I override a getter on a property when using Core Data?

I want to be able to override the getter on a string property on one of my core data models and inside the getter I need to find out what the value is for that property.

@interface LabTest : NSManagedObject {
}
@property (nonatomic, retain) NSString *status;
@end

@implementation LabTest

@dynamic status;

- (NSString *)status {
NSString *tempStatus = [super valueForKey:@"status"];
//do some checking here
return tempStatus;
}

@end


The code above crashes the process. I have tried a few different things, but I think they all end up in an infinite loop with the program crashing with a code of 139.

What is the correct way to access a core data member in the getter like this?

Answer

Have you tried [self primitiveValueForKey:@"status"] instead of [super valueForkey:@"status"]?

Comments