Skip to content

Instantly share code, notes, and snippets.

@kognate
Created August 25, 2010 17:59
Show Gist options
  • Save kognate/549981 to your computer and use it in GitHub Desktop.
Save kognate/549981 to your computer and use it in GitHub Desktop.
/**
* winCount
* returns the count of all games that the human player won.
*
* @returns int
*/
+(int) winCount {
NSError *error;
NSManagedObjectContext *context = [(BFHeartsAppDelegate *)[UIApplication sharedApplication].delegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"GameFinalScore" inManagedObjectContext:context];
NSFetchRequest *req = [[NSFetchRequest alloc] init];
[req setEntity:entityDesc];
NSPredicate *onlywins = [NSPredicate predicateWithFormat:@"playerWon == YES"];
[req setPredicate:onlywins];
NSUInteger cnt = [context countForFetchRequest:req error:&error];
[req release];
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment