Skip to content

Instantly share code, notes, and snippets.

@martin-cotta
Created April 11, 2016 23:44
Show Gist options
  • Save martin-cotta/6b513d20800fa46544461f4b126f4af6 to your computer and use it in GitHub Desktop.
Save martin-cotta/6b513d20800fa46544461f4b126f4af6 to your computer and use it in GitHub Desktop.
self reference inside a block, weakSelf and strongSelf
__weak __typeof__(self) weakSelf = self;
dispatch_group_async(_operationsGroup, _operationsQueue, ^{
__typeof__(self) strongSelf = weakSelf;
[strongSelf doSomething];
[strongSelf doSomethingElse];
});
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let strongSelf = self {
strongSelf.doSomething()
strongSelf.doSomethingElse()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment