-
-
Save mikeabdullah/2209110 to your computer and use it in GitHub Desktop.
- (BOOL)saveAndReturnError:(NSError **)error | |
{ | |
NSManagedObjectContext *context = [self managedObjectContext]; | |
__block BOOL result; | |
[context performBlockAndWait:^{ | |
result = [context save:error]; | |
if (!result && error) [*error retain]; | |
}]; | |
if (!result && error) [*error autorelease]; | |
return result; | |
} |
I'm not entirely sure. I notice the frameworks declare the error pointer in more detail under ARC, so I think they have specific terminology to describe how the error needs to be handled. We're stuck on 32 bit so no ARC for me!
I'll investigate, but I it should be safe, as you have a strong reference to the NSError back in the caller, which should keep it around until that reference goes away... although ARC is pretty aggressive about releasing local variables that you are no longer using...
I think it is fine because (NSError *_) implies (_autoreleasing NSError) under ARC. And the block should capture the pointer to the actual NSError object that has a strong reference as a local variable to the caller. (and it seems to work fine in my tests :)
Awesome stuff, was just thinking about this today, the original should be safe under ARC though?