I want to use the results array after performing the block, my question is, should the results array instance be retained because it was originated from a block?
__block NSError *error = nil;
__block NSArray *results;
[moc performBlockAndWait:^(void) {
results = [moc executeFetchRequest:fetchRequest error:&error];
[results retain];
}];
if(results){
//Do somehting
}
To be pedantically correct, you would do something like:
That is, you want a hard retain maintained from inside the block to outside the block always and regardless of synchronous execution. That retain must be balanced.
The over-arching rule is all about thread transfer; you are transferring objects from one thread of execution (wherever the block was executed) to the calling thread. There must be a hard retain across that transfer of ownership.