views:

284

answers:

2

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?

+8  A: 

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

John Franklin
There is what I was looking for. Thanks!
Tony Eichelberger
+1  A: 

The managed object creator in x-code has a checkbox that is normally unchecked just for this purpose.

Validation Methods

NWCoder
I am not quite doing validation, since I still want to return a value, I just may want to change it a little in some cases. Thanks.
Tony Eichelberger