Created
November 22, 2009 06:22
-
-
Save Kentzo/240465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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