I'm using the code below to Fetch a queried set of all rows using CoreData matching the search criteria: itemType = 1. But what I need to do is to Fetch a specific number of Random rows from the data instead. For example, instead of retrieving all 100 rows of data in which the column name dataType = 1, I need to get 25 rows randomly in which dataType = 1. I'm hoping there is relatively painless solution. Any help is appreciated. lq
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"MyAppName"
inManagedObjectContext:[self managedObjectContext]]];
NSError *error = nil;
NSPredicate *predicate;
NSArray *fetchResults;
predicate = [NSPredicate predicateWithFormat:@"(itemType = %i)", 1];
[request setPredicate:predicate];
fetchResults = [managedObjectContext executeFetchRequest:request error:&error];
if (!fetchResults) {
// NSLog(@"no fetch results error %@", error);
}
self.mutableArrayName = [NSMutableArray arrayWithArray:fetchResults];
[request release];