The design pattern below appears a few times in my app. I'm in the midst of converting to ARC. Can someone corroborate whether __unsafe_retained __block
is correct usage?
__unsafe_unretained __block id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MyNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
[[NSNotificationCenter defaultCenter] removeObserver:observer];
// ...
}];
Some notes:
__unsafe_unretained
is used because deployment target is 10.6__block
is used because otherwiseobserver
would be captured by the block prematurely- Xcode's ARC migration tool added
__unsafe_unretained
for me. Is it necessary? I realize that without it the block will retainobserver
, but is that so bad? Would it lead to a retain cycle?