Search code examples
reactive-cocoalibextobjc

Explanation of how weakify and strongify work in ReactiveCocoa / libextobjc


I understand that you should use @weakify @strongify to avoid retain cycles but I don't completely understand how they actually achieve this?


Solution

  • When writing the question I stared harder at the macro definitions and I think it works as you might guess.

    @weakify creates a new weakly referenced variable of the same type you pass in and assigns the original value to it

    @strongify creates a variable that matches the original variable but it exists in the local scope and assigns to it the variable created by @weakify