Consider this:
id observer = [[NSNotificationCenter defaultCenter]
addObserverForName:MyNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
[[NSNotificationCenter defaultCenter]
removeObserver:observer
name:MyNotification
object:nil
];
// do other stuff here...
}
];
I'm using this pattern to observe a notification once and then stop observing it. But LLVM tells me (under ARC) that Variable 'observer' is uninitialized when captured by block.
How can I fix this, since the block necessarily captures the variable before initialization, it being part of the initializer? Will using the __block
qualifier on observer
do the trick?