Created
March 15, 2011 04:20
-
-
Save hanksudo/505f5de676eaa816954f to your computer and use it in GitHub Desktop.
CoreData Update Record Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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