Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created March 15, 2011 04:20
Show Gist options
  • Save hanksudo/505f5de676eaa816954f to your computer and use it in GitHub Desktop.
Save hanksudo/505f5de676eaa816954f to your computer and use it in GitHub Desktop.
CoreData Update Record Sample
Statistic *statistic = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Statistic" inManagedObjectContext:context];
request.predicate = [NSPredicate predicateWithFormat:@"level = %i", _level];
statistic = [[context executeFetchRequest:request error:nil] lastObject];
[request release];
float currentHighScore = [statistic.score floatValue];
if (currentHighScore < _score) {
[statistic setValue:[NSNumber numberWithInt:_level] forKey:@"level"];
[statistic setValue:[NSNumber numberWithFloat:_score] forKey:@"score"];
[statistic setValue:[NSNumber numberWithInt:_touches] forKey:@"touches"];
[statistic setValue:[NSNumber numberWithFloat:_time] forKey:@"time"];
[statistic setValue:[NSNumber numberWithInt:_cleared] forKey:@"cleared"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment