Skip to content

Instantly share code, notes, and snippets.

@jk
Forked from krzysztofzablocki/gist:6711189
Last active December 23, 2015 23:49
Show Gist options
  • Save jk/6712065 to your computer and use it in GitHub Desktop.
Save jk/6712065 to your computer and use it in GitHub Desktop.
- (void)main {
__weak id obj;
// Wrong:
dispatch_async(queue, ^() {
[obj doSomething];
[obj doSomethingElse]; // can turn to nil at any point, should store in strong at beggining of block
[obj doSomethingElse2];
});
// Ok:
__weak id obj;
dispatch_async(queue, ^() {
[obj doSomethingAbstract]; // either everything or nothing will execute, no need for strong storage
});
}
- (void)doSomethingAbstract {
[self doSomething];
[self doSomethingElse];
[self doSomethingElse2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment