Created
December 3, 2012 10:12
-
-
Save gonzalezreal/4194038 to your computer and use it in GitHub Desktop.
Como evitar referencias circulares cuando usamos ARC con bloques
This file contains hidden or 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
// 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