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
After adding the code suggested below the output is this:
Object: (entity: StatTracker; id: 0x3e1e1b0 ; data: ) 2010-05-19 11:30:38.173 verses[29526:207] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: the entity StatTracker is not key value coding-compliant for the key "timesLauched".' 2010-05-19 11:30:38.174 verses[29526:207] Stack: (