MTLManagedObjectAdapter
MTLManagedObjectAdapter copied to clipboard
Fix error is not assigned correctly.
when error is used inside a block of -enumerateKeysAndObjectsUsingBlock:. It setups an autorelease pool, by the time it returns, any out error will be deallocaed. we need to use __block, as in code *tmpError
I assume put error in enumerateKeysAndObjectsUsingBlock is equal to code below.
- (void)produceError3:(NSError **)error {
void (^errorProduceBlock)() = ^{
@autoreleasepool {
*error = [NSError errorWithDomain:@"AWESOME ERROR" code:0 userInfo:nil];
}
};
errorProduceBlock();
}
- (void)produceError5:(NSError **)error {
[@{@"DD":@"YY"} enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
*error = [NSError errorWithDomain:@"AWESOME ERROR" code:0 userInfo:nil];
}];
}
Both code will crash. But I don't know why MTLManagedObjectAdapter won't crash, it will just silently ignore the error.
I think this also addressed some of the discussion in https://github.com/Mantle/Mantle/pull/120