Capturing More Than `self`
- Tags:
- swift
A common pattern when using closures in Swift is to add [weak self]
in the captures list to hold a weak reference to self
and avoid a retain cycle. This is then often followed by the following:
guard let self = self else { return }
But I often forget that capture lists can capture other variables in the current scope, so I thought I'd highlight some other use cases.