弱 self 捕获

版本新特性 / Swift 5.7

class WeakSelfCaptures: NSObject {
    var count = 10

    func example() {
        let showCount = { [weak self] in
            guard let self else { return }
            print("count is \(count)")
        }

        showCount()
    }
} 


SE-0365 takes another step towards letting us remove self from closures by allowing an implicit self in places where a weak self capture has been unwrapped.