I am a new bet in iOS. I am using NSManagedObject from Core Data to perform Insert and Fetch operations. It works great. But the problem is that I want to extract from the table only some selected records (where is the condition in MySQL). E.g. "select a name from users, where city = 'Pune'"; I found NSPredicate to get filtered data. But it gives all the data in the array, not just the selected one. E.g. if the result for the request is higher:
Anu
Then the result of NSPredicate will give:
fname = Anu
lname = Padhye
city = Pune
id = 3
Is there a way to only select selected entries in iOS Objective-c? The following is a snippet of the code I'm using for NSManagedObject:
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"User"];
valueData = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSEntityDescription *productEntity=[NSEntityDescription entityForName:@"User" inManagedObjectContext:managedObjectContext];
NSFetchRequest *fetch=[[NSFetchRequest alloc] init];
[fetch setEntity:productEntity];
NSPredicate *p=[NSPredicate predicateWithFormat:@"id == %d", 3];
[fetch setPredicate:p];
NSError *fetchError;
NSArray *fetchedProducts=[valueData filteredArrayUsingPredicate:p];