i am trying to avoid memory leak using clousures in swift , but swift is not recognising the [weak self] inside the closure.
// 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
, it's missingin
.weak
isn't possible.