Ios OperationQueue cancelAllOperations未将值更改为isCancelled 我已经实现了自己的“MyOperation”和“MyOperationQueue”。
MyOperation:实现Ios OperationQueue cancelAllOperations未将值更改为isCancelled 我已经实现了自己的“MyOperation”和“MyOperationQueue”。,ios,swift,nsoperation,nsoperationqueue,Ios,Swift,Nsoperation,Nsoperationqueue,MyOperation:实现 private var _executing : Bool = false override var isExecuting : Bool { get { return _executing } set { guard _executing != newValue else { return } willChangeValue(forKey: "isExecuting")
private var _executing : Bool = false
override var isExecuting : Bool {
get { return _executing }
set {
guard _executing != newValue else { return }
willChangeValue(forKey: "isExecuting")
_executing = newValue
didChangeValue(forKey: "isExecuting")
}
}
private var _finished : Bool = false
override var isFinished : Bool {
get { return _finished }
set {
guard _finished != newValue else { return }
willChangeValue(forKey: "isFinished")
_finished = newValue
didChangeValue(forKey: "isFinished")
}
}
override func finish() {
// This will call OpeationQueue delegate method once completes
_executing = false
_finished = true
}
override func start() {
if self.isCancelled {
finish()
return
}
super.start()
_executing = true
// Do some network operation
}
override func cancel() {
super.cancel()
if self.isExecuting{
networkRequest?.cancel()
self.finish()
}
}
override func finish() {
_executing = false
_finished = true
}
我正在呼叫myoperationqueue.CancelAllOperations()
这不会触发我在操作中被取消
此实现有什么问题。显示更多相关代码。队列实例化、取消…显示更多相关代码。队列实例化、取消。。。