MTLManagedObjectAdapter icon indicating copy to clipboard operation
MTLManagedObjectAdapter copied to clipboard

Fix error is not assigned correctly.

Open caoer opened this issue 9 years ago • 1 comments

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.

caoer avatar Jul 02 '15 18:07 caoer

I think this also addressed some of the discussion in https://github.com/Mantle/Mantle/pull/120

caoer avatar Jul 02 '15 18:07 caoer