[swift-users] KVC - KeyPath in Operation

Tony Parker anthony.parker at apple.com
Fri Jun 16 11:11:33 CDT 2017


Hi Rod,

Thanks, we’re looking into it.

- Tony

> On Jun 15, 2017, at 9:14 PM, Rod Brown <rodney.brown6 at icloud.com> wrote:
> 
> Hi Tony and Somu,
> 
> I have an open radar for this one which has been outstanding for a few months.
> 
> Radar #32191242
> 
> Hope this helps.
> 
> - Rod
> 
> 
> 
>> On 15 Jun 2017, at 10:27 am, Tony Parker via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> Hi Somu,
>> 
>> You can certainly file a bug for us. It may be something we are already tracking or already fixed, but the bug report will let us double check that.
>> 
>> Thanks,
>> - Tony
>> 
>>> On Jun 13, 2017, at 12:33 PM, somu subscribe via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>> 
>>> Thanks a lot Jordan for pointing out the root cause.
>>> 
>>> The underlying executing and finished properties are readonly properties.
>>> 
>>> For an Asynchronous operation I had to override it tell when the asynchronous operation completes. 
>>> 
>>> Since they are readonly properties I am unable to call the super on them to set values.
>>> 
>>> I can still use String, was just wondering if there was a way to do it using KeyPath. It is more out of enthusiasm to try out the KeyPath feature in the project :) 
>>> 
>>> Would it be appropriate to file a bug report for the implementation of Operation ?
>>> 
>>> Thanks and regards,
>>> Muthu
>>> 
>>> 
>>> 
>>>> On 14 Jun 2017, at 1:32 AM, Jordan Rose <jordan_rose at apple.com <mailto:jordan_rose at apple.com>> wrote:
>>>> 
>>>> Hi, Muthu. This is a longstanding issue with Operation—the Objective-C name of the property is just "executing", but the KVO keys that the implementors used is "isExecuting". Swift isn't set up to deal with this difference.
>>>> 
>>>> Fortunately, the base implementation of Operation already knows how to send the KVO notifications, so you shouldn't have to override these properties at all. If you still want to for some other reason, you can call super instead of storing to a private property.
>>>> 
>>>> Hope that helps,
>>>> Jordan
>>>> 
>>>> 
>>>>> On Jun 13, 2017, at 06:40, somu subscribe via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>>>> 
>>>>> 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
>>>>> _______________________________________________
>>>>> swift-users mailing list
>>>>> swift-users at swift.org <mailto:swift-users at swift.org>
>>>>> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>>>> 
>>> 
>>> _______________________________________________
>>> swift-users mailing list
>>> swift-users at swift.org <mailto:swift-users at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170616/a0e53d75/attachment.html>


More information about the swift-users mailing list