I have created an AsyncOperation which is a subclass of Operation.
I am overriding the following methods to use KVC:
- isExecuting
- isFinished
Problem:
When I use String in place of KeyPath, my completion block gets executed. If I use KeyPath the completion block of the operation is not getting executed.
Works ok:
willChangeValue(forKey: "isExecuting")
didChangeValue(forKey: "isExecuting")
willChangeValue(forKey: "isFinished")
didChangeValue(forKey: "isFinished")
Doesn't work (Compiles ok, but at runtime the completion block doesn't get executed):
willChangeValue(for: \.isExecuting)
didChangeValue(for: \.isExecuting)
willChangeValue(for: \.isFinished)
didChangeValue(for: \.isFinished)
Note: I am using the following:
- macOS 10.12.5 (16F73)
- Xcode 9.0 beta (9M136h)
Questions:
1. Why isn't KeyPath working when using the String works ?
2. How to fix using KeyPath ?
Complete Code:
class AsyncOperation : Operation {
private var _executing = false
private var _finished = false
override var isExecuting : Bool {
get {
return _executing
}
set {
willChangeValue(for: \.isExecuting
_executing = newValue
didChangeValue(for: \.isExecuting)
}
}
override var isFinished : Bool {
get {
return _finished
}
set {
willChangeValue(for: \.isFinished)
_finished = newValue
didChangeValue(for: \.isFinished)
}
}
override var isAsynchronous : Bool {
return true
}
func markAsCompleted() {
isExecuting = false
isFinished = true
}
}