Skip to content

Instantly share code, notes, and snippets.

@gonzalezreal
Created December 3, 2012 10:12
Show Gist options
  • Save gonzalezreal/4194038 to your computer and use it in GitHub Desktop.
Save gonzalezreal/4194038 to your computer and use it in GitHub Desktop.
Como evitar referencias circulares cuando usamos ARC con bloques
// Este código crea una referencia circular entre 'operation' y self
self.operation = [NSBlockOperation blockOperationWithBlock:^{
[self doSomething];
}];
// Para evitarlo tenemos pasarle al bloque una referencia débil a self
typeof(self) __weak w_self = self;
self.operation = [NSBlockOperation blockOperationWithBlock:^{
// Es importante convertir la referencia débil en una referencia fuerte
// dentro del mismo bloque
typeof(self) s_self = w_self;
[s_self doSomething];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment