提问人:Code cracker 提问时间:6/22/2021 更新时间:11/25/2022 访问量:3191
在 iOS swift 范围内找不到“弱”
Cannot find 'weak' in scope iOS swift
问:
我试图在 Swift 中使用 clousures 避免内存泄漏,但 Swift 没有识别闭包内的 [弱自我]。
// class :
class LanguageClass {
var languageClosure : (() -> ())?
var name : String = ""
init() {
self.languageClosure = { [weak self]
print("\(self.name) is the language")
}
}
deinit {
print("deinitialized")
}
}
// consumption :
var swiftLanguage : LanguageClass? = LanguageClass()
swiftLanguage?.name = "Swift"
swiftLanguage?.languageClosure?()
swiftLanguage = nil
答: 暂无答案
评论
[weak self] in
,它不见了.in
weak