ARC-Block-Avoid retain cycles and crashes


Using blocks which captures self (explicitly or automatically by referencing an iVar!) you have the chance to a retain cycle where the block keeps self and self keeps the block or a crash when self is released.

This is true for Obj-C as well as for Swift.

The proper usage declared by Apple itself: store self in a weak ref and in the block put it to strong ref to avoid the release of self just in the time the code runs.

Apple link: Transitioning to Arc RC and search for the section: “For non-trivial cycles, however, you should use”

Looks strange but if you think carefully you realize how efficient the solution is.

For a more deeper explanation see: this post