Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vinzenzweber/512680 to your computer and use it in GitHub Desktop.
Save vinzenzweber/512680 to your computer and use it in GitHub Desktop.
/**
* Return an array with SFMediaItems found in the local database for the given predicate.
*/
-(NSArray *)fetchSFMediaItemWithPredicateFormat:(NSString *)format, ... {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SFMediaItem" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
va_list args;
va_start(args, format);
NSPredicate *predicate = [NSPredicate predicateWithFormat:format arguments:args];
va_end(args);
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [self.managedObjectContext executeFetchRequest:request error:&error];
if (error != nil) {
NSLog(@"ERROR FETCHING DATA FROM DB FOR PREDICATE");
}
[request release];
return array;
}
/**
* Return how many SFMediaItems are found in the local database for the given predicate.
*/
-(NSUInteger)countSFMediaItemWithPredicateFormat:(NSString *)format, ... {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SFMediaItem" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
va_list args;
va_start(args, format);
NSPredicate *predicate = [NSPredicate predicateWithFormat:format arguments:args];
va_end(args);
[request setPredicate:predicate];
NSError *error = nil;
NSUInteger count = [self.managedObjectContext countForFetchRequest:request error:&error];
if (error != nil) {
NSLog(@"ERROR COUNT DATA FROM DB FOR PREDICATE");
}
[request release];
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment