MyOperation:实施
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.cancellallOperations() 这并没有触发我的操作上的isCancelled。
此实现有什么问题。