-
-
Save jk/6712065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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