Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>// Fetch objects with a predicate +(NSMutableArray *)searchObjectsForEntity:(NSString*)entityName withPredicate:(NSPredicate *)predicate andSortKey:(NSString*)sortKey andSortAscending:(BOOL)sortAscending andContext:(NSManagedObjectContext *)managedObjectContext { // Create fetch request NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedObjectContext]; [request setEntity:entity]; // If a predicate was specified then use it in the request if (predicate != nil) [request setPredicate:predicate]; // If a sort key was passed then use it in the request if (sortKey != nil) { NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:sortAscending]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; } // Execute the fetch request NSError *error = nil; NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&amp;error] mutableCopy]; // If the returned array was nil then there was an error if (mutableFetchResults == nil) NSLog(@"Couldn't get objects for entity %@", entityName); // Return the results return mutableFetchResults; } </code></pre> <p>You can use this helper method with desired parameters.</p> <p>Update: After reading the comments. First you need something like this <a href="http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started" rel="nofollow">http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started</a> then you can use above method for fetching the items.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload