[swift-evolution] [Review #2] SE-0161: Smart KeyPaths: Better Key-Value Coding for Swift
Ricardo Parada
rparada at mac.com
Thu Apr 6 12:30:30 CDT 2017
Yes but that is a bit different. Spaces can be used for clarity or breaking up a chain into multiple lines maybe. But, the space is not really part of the key path. I would expect the key path to be typed in without spaces when using the special syntax.
> On Apr 6, 2017, at 12:45 PM, Ben Rimmington <me at benrimmington.com> wrote:
>
>
>> On 6 Apr 2017, at 16:29, Ricardo Parada via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> Another thought on the use of single quotes (an possibly the proposed escape character). Do you think the closing single quote could be made optional since key paths cannot have spaces? Or would that be confusing for beginners?
>
> Key paths can (probably) have spaces:
>
> Welcome to Apple Swift version 3.1 (swiftlang-802.0.48 clang-802.0.48).
> 1> Double.nan.isNaN
> $R0: Bool = true
> 2> Double . nan . isNaN
> $R1: Bool = true
> 3> Double .nan .isNaN
> $R2: Bool = true
> 4> Double. nan. isNaN
> error: extraneous whitespace after '.' is not permitted
> Double. nan. isNaN
> ^~
>
>> For example, these two would be equivalent:
>>
>> let isPuppyPredicate = 'Pet.type == .dog && 'Pet.age < 12
>> let isPuppyPredicate = 'Pet.type' == .dog && 'Pet.age' < 12
>>
>> Or this:
>>
>> let isPuppyPredicate = \Pet.type == .dog && \Pet.age < 12
>> let isPuppyPredicate = \Pet.type\ == .dog && \Pet.age\ < 12
>>
>> You would use the closing character normally when wanting to invoke a method on the key path object.
>>
>> Any thoughts?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170406/d50e1cdd/attachment.html>
More information about the swift-evolution
mailing list