I would like someone's help to understand the correct use of weak self in nested escaping blocks. It would be great if someone could tell me whether what I'm doing below is correct. Thank you.
import UIKit
class MyClass {
var closingTimer: Timer?
func f1() {
/**
Some work here
*/
}
func f2() {
closingTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval.init(5), repeats: true, block: { [weak self] (t: Timer) in
/**
Some work here
*/
if let _ = self {
DispatchQueue.main.async { [weak self] in
self?.f1()
}
}
})
}
}