Skip to content

Instantly share code, notes, and snippets.

@yasirmturk
Created November 30, 2011 07:38
Show Gist options
  • Save yasirmturk/1408349 to your computer and use it in GitHub Desktop.
Save yasirmturk/1408349 to your computer and use it in GitHub Desktop.
A generic core data function to Get a record based on the criteria
/*
* Get a record based on the criteria
*/
- (id)getRecordFromEntity:(NSString *)entity whereField:(NSString *)fieldName isEqualTo:(id)val
{
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %@)", fieldName, val];
//NSLog(@"(P: %@)", [pred predicateFormat]);
NSArray *arr = [self queryDBForEntity:entity predicate:pred sortByField:fieldName];
//NSLog(@"%@", arr);
if ([arr count] > 0)
return [arr objectAtIndex:0];
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment