简体   繁体   中英

Do I need [weak self] or [unowned self] for a Singleton in the Closure?

class Test {

    private init() {}

    static let shared = Test()

    func test() {

    }

}

let closure: ()->Void = {
    Test.shared.test()
}

closure()

The code above is simple. But i want to know if I have to mark weak or unowned to the Singleton. And why?

不,因为在该闭包中未使用(显式或隐式) self

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM