OperationQueue cancelAllOperations未将值更改为isCancelled

时间:2017-07-05 09:49:03

标签: ios swift nsoperation nsoperationqueue

我实施了自己的" MyOperation"和#34; MyOperationQueue"两者。

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。

此实现有什么问题。

0 个答案:

没有答案