Skip to content

Instantly share code, notes, and snippets.

@Vyazovoy
Created June 25, 2013 12:49
Show Gist options
  • Save Vyazovoy/5858195 to your computer and use it in GitHub Desktop.
Save Vyazovoy/5858195 to your computer and use it in GitHub Desktop.
Right way to use references inside blocks
NSObject *someReferencedObject = [NSObject new];
__typeof(someReferencedObject) __weak weakSomeReferencedObject = someReferencedObject;
[someReferencedObject addBlock:^() {
__typeof(weakSomeReferencedObject) __strong strongSomeReferencedObject = weakSomeReferencedObject;
if (strongSomeReferencedObject) {
//do something with strongSomeReferencedObject
} else {
//appropriate reaction
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment