Saafo
(Saafo)
1
I have a class and a lazy var inside, like this:
class C {
lazy var btn = {
let btn = UIButton()
btn.addBlock { [weak self] self?.xxx() }
return btn
}
}
However, the compiler said: "Cannot find 'weak' in scope"
If I change to this, it works:
class C {
lazy var btn = {
let btn = UIButton()
weak var ws = self
btn.addBlock { ws?.xxx() }
return btn
}
}
So, can't we use "[weak xxx]" to weak something inside a block inside a lazy var property statement?
jaleel
(Jaleel Akbashev)
2
You're missing in, so should be btn.addBlock { [weak self] in self?.xxx() }
2 Likes
Saafo
(Saafo)
3
Ohhhh I'm so stupid..... Thanks!!
1 Like
jaleel
(Jaleel Akbashev)
4
Np, always make this mistake also 
1 Like