Skip to content

Instantly share code, notes, and snippets.

@krzysztofzablocki
Created September 26, 2013 08:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krzysztofzablocki/6711189 to your computer and use it in GitHub Desktop.
Save krzysztofzablocki/6711189 to your computer and use it in GitHub Desktop.
Multiple weak call
Wrong:
__weak id obj;
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