Created
August 7, 2010 10:53
-
-
Save vinzenzweber/512680 to your computer and use it in GitHub Desktop.
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
/** | |
* 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; | |
} |
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
/** | |
* 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