Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 495
Tony Eichelberger Avatar asked Dec 18 '09 19:12

Tony Eichelberger


1 Answers

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

like image 103
John Franklin Avatar answered Sep 23 '22 01:09

John Franklin