swift懶加載的閉包內(nèi)部使用self,不會(huì)導(dǎo)致循環(huán)引用,原因是因?yàn)?code>swift的懶加載閉包是非逃逸閉包@noescape
什么是@noescape,@escaping
非逃逸閉包(@noescape): 在這個(gè)函數(shù)結(jié)束前閉包被調(diào)用
逃逸閉包(@escape): 在這個(gè)函數(shù)結(jié)束后閉包才被調(diào)用
非逃逸閉包內(nèi)使用self是不會(huì)導(dǎo)致循環(huán)引用,例如SnapKit使用
self.view.addSubview(box)
box.backgroundColor = .green
box.snp.makeConstraints { (make) -> Void in
make.width.height.equalTo(50)
make.center.equalTo(self.view)
}