Figure

A blog about Swift and iOS development.

Dealing with Weak in Closure-based Delegation

This post by Oleg Dreyman is so clever, clear, and useful, I'm temped to call it a must read.

In a nutshell, using closures for delegates puts the responsibility of ownership management on the delegatee rather than the delegator. But by packaging the delegate into a setter, Oleg shows us we can control how it’s captured with respect to the closure (and, as a bonus, reduce our free-floating closures with more trailing closure syntax).

While I'm not sold this needing to be its own dependency, I'm absolutely going to adopt the pattern post haste. Thanks, Oleg!


Hit me up on twitter (@jemmons) to continue the conversation.

Latest | Archives