iPhone OS: Why is my managedModelObject not complying with Key Value Coding?
- by nickthedude
Ok so I'm trying to build this stat tracker for my app and I have built a data model object called statTracker that keeps track of all the stuff I want it to. I can set and retrieve values using the selectors, but if I try and use KVC (ie setValue: forKey: ) everything goes bad and says my StatTracker class is not KVC compliant:
valueForUndefinedKey:]: the entity StatTracker is not key value coding-compliant for the key "timesLauched".'
2010-05-18 15:55:08.573
here's the code that is triggering it:
NSArray *statTrackerArray = [[NSArray alloc] init];
statTrackerArray = [[CoreDataSingleton sharedCoreDataSingleton] getStatTracker];
NSNumber *number1 = [[NSNumber alloc] init];
number1 = [NSNumber numberWithInt:(1 + [[(StatTracker *)[statTrackerArray objectAtIndex:0] valueForKey:@"timesLauched"] intValue])];
[(StatTracker *)[statTrackerArray objectAtIndex:0] setValue:number1 forKey:@"timesLaunched" ];
NSError *error;
if (![[[CoreDataSingleton sharedCoreDataSingleton] managedObjectContext] save:&error]) {
NSLog(@"error writing to db");
}
Not sure if this is enough code for you folks let me know what you need if you do need more.
This would be so sweet if I could use KVC because I could then abstract all this stat tracking stuff into a single method call with a string argument for the value in question. At least that is what I hope to accomplish here. I'm actually now understanding the power of KVC but now I'm just trying to figure out how to make it work.
Thanks!
Nick