【Swift】block防止self循环引用
2021-12-02 本文已影响0人
FineFan
方法1、
weak var weakSelf =self
self.block = {() -> () in
if let strongSelf = weakSelf {
//使用self
}
}
方法2、
self.block = {[weak self]() -> () in
//使用self?
}
方法1、
weak var weakSelf =self
self.block = {() -> () in
if let strongSelf = weakSelf {
//使用self
}
}
方法2、
self.block = {[weak self]() -> () in
//使用self?
}