NSTimer循环引用
```
extension Timer {
class func fp_scheduledTimer(timeInterval ti:TimeInterval, userInfo: (()->Void)?, repeats yesOrNo:Bool) ->Timer{
return scheduledTimer(timeInterval: ti, target:self, selector:#selector(timer_block(timer:)), userInfo: userInfo , repeats: yesOrNo)
}
@objc class func timer_block(timer:Timer) {
let block:(()->Void)? = timer.userInfo as? (() ->Void)
if block!=nil{
block!()
}
}
}
//调用
timer=Timer.fp_scheduledTimer(timeInterval:1, userInfo: { [weak self]in
guard let strongSelf =self else{return}
strongSelf.onTimer()
}, repeats:true)
timer.fire()
@objcfunconTimer() ->Void{
print("timer")
}
```
网友评论