[swift-users] KVC - KeyPath in Operation

somu subscribe somu.subscribe at gmail.com
Tue Jun 13 08:40:22 CDT 2017


Hi,

I am having trouble using KeyPath to KVC (Key Value Code) in Swift 4.

I have a subclass of Operation and I am overriding the isFinished and isExecuting property.

Problem:
- When I use KeyPath, the completionBlock of the operation is not invoked.
- However when I use String instead of KeyPath, the completionBlock is invoked.

Questions:
- Am I missing something ? 
- Is there a way to fix it using KeyPath ?

Code:

    override var isExecuting : Bool {
        
        get {
            return _executing //property in the class
        }
        
        set {
            willChangeValue(for: \.isExecuting)
            _executing = newValue
            didChangeValue(for: \.isExecuting)
        }
    }
    
    override var isFinished : Bool {
        
        get {
            return _finished //property in the class
        }
        
        set {
            willChangeValue(for: \.isFinished)
            _finished = newValue
            didChangeValue(for: \.isFinished)
        }
    }


Configuration:
- Xcode - 9.0 beta (9M136h) 
- Tested on Simulator (iOS 11)
- macOS Sierra - 10.12.5 (16F73)


Thanks and Regards,
Muthu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170613/9e68988b/attachment.html>


More information about the swift-users mailing list