With closures I usually append [weak self]
onto my capture list and then do a null check on self:
func myInstanceMethod()
{
let myClosure =
Unfortunately, only Closures have "Capture List" feature like [weak self]
. For nested functions, You have to use normal weak
or unowned
variables.
func myInstanceMethod() {
weak var _self = self
func nestedFunction(result : Bool) {
_self?.anotherInstanceMethod()
}
functionExpectingClosure(nestedFunction)
}