Skip to content

Instantly share code, notes, and snippets.

@Kentzo
Created November 22, 2009 06:22
Show Gist options
  • Save Kentzo/240465 to your computer and use it in GitHub Desktop.
Save Kentzo/240465 to your computer and use it in GitHub Desktop.
void RMPrintError(NSError* error){
NSArray* errors = [[error userInfo] valueForKey:@"NSDetailedErrors"];
if(errors != nil){
for(NSError* nestedError in errors){
NSLog(@"%@", [nestedError userInfo]);
}
}
else{
NSLog(@"%@", error);
}
NSLog(@"\n");
}
@implementation NSManagedObjectContext (MyContext)
- (id)fetchRequestWithEntity:(NSEntityDescription*)entity predicateOrNil:(NSPredicate*)predicate{
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setPredicate:predicate];
NSError* error = nil;
id result = [self executeFetchRequest:request error:&error];
[request release];
if(result == nil){
RMPrintError(error);
NSException* exception = [NSException exceptionWithName:RMFetchRequestException
reason:[NSString stringWithFormat:@"Cannot fetch %@", [entity name]]
userInfo:[error userInfo]];
@throw exception;
}
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment