Setting up a NSFetchRequest equivalent to SELECT status in SQL.
Here is a simple example:
NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:[NSEntityDescription entityForName:@"EntityName" inManagedObjectContext:moc]]; NSError *error = nil; NSArray *results = [moc executeFetchRequest:request error:&error]; // error handling code
The results array contains all of the managed objects contained in the sqlite file. If you want to capture a specific object (or more objects), you need to use a predicate with this query. For example:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == %@", @"Some Value"]; [request setPredicate:predicate];
In this case, results contains objects where the attribute is equal to Some Value . Setting the predicate is equal to the position of the WHERE clause in the SQL statement.
Note
I assume that the name of the EntityName object and its property is called attribute , which has a type string.
For more information, I suggest you read the Master Data Programming Guide and the link to NSFecthRequest .
Hope this helps.
Lorenzo b
source share