Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Added Core Data Fetch boilerplate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkylerLutz committed Sep 5, 2013
1 parent eac144c commit 71db226
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cdfetch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Core Data Fetch
// Boilerplate code for a simple Core Data fetch
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation

id context = [[[UIApplication sharedApplication] delegate] managedObjectContext];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:<#entityName#> inManagedObjectContext:context];
[request setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:<#predicateFormat#>];
[request setPredicate:predicate];

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:<#key#> ascending:<#isAscending#>];
[request setSortDescriptors:@[sortDescriptor]];

NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:request error:&error];

if (error) {

NSLog(<#Error Message#>);
}

0 comments on commit 71db226

Please sign in to comment.