The strong weak pattern

To allow editors to disappear if they go out of scope but properly perform the edit if they are still around when closure executes, you can create a temporary strong reference to self. Update editTutorial as follows:

func editTutorial() { queue.async() {

[weak self] in

guard let strongSelf = self else { return

}

DispatchQueue.main.async { print(strongSelf.feedback)

}

}

}

This code is all or nothing. If the editor has gone away when the closure eventually runs, it will do nothing. If strongSelf is not nil it will stick around until the print statement finishes.

results matching ""

    No results matching ""