使用 NSTimer 后,类 deinit 方法永远不会被调用。该类是用 Swift 编写的,我在“init”处调用计时器,如下所示:
init(eventsDistributor : EventsDistributor, orderSide : ORDER_SIDE, stockViewModel : StockViewModel, orderType : ORDER_TYPE_ENUM, orderPrice : NSNumber) {
self.eventsDistributor = eventsDistributor
self.orderSide = orderSide
self.stockViewModel = stockViewModel
self.orderType = orderType
self.orderPrice = orderPrice
super.init()
_events()
loadPreOrderDetails()
//Here I call the Timer:
var reloadTimer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: "loadSecurityTradeInfo", userInfo: nil, repeats: true)
reloadTimer.fire()
}
我也尝试将其NSTimer
用作局部变量,但没有成功......有人遇到这个问题吗?我可以在 Swift 中使用不会导致类不被释放的计时器吗?谢谢