I agree, there's an analogy between strings and key paths, and in that regards the single quote would make sense. I would not complain.
> On Apr 6, 2017, at 11:08 AM, Sean Heber via swift-evolution > <swift-evolution@swift.org> wrote: > >>> That's an interesting point. While `\` alone seems acceptable, I think it's >>> unfortunate that we'll have `(\...)` and `\(...)` both in the language. >>> Can we maybe consider instead: >>> >>> let firstFriendsNameKeyPath = \Person.friends[0].name\ >> >> 'Single quotes' (i.e. U+0027 APOSTROPHE) are available AFAIK: >> >> // Create a key path and use it >> let firstFriendsNameKeyPath = 'Person.friends[0].name' >> luke[keyPath: firstFriendsNameKeyPath] // "Han Solo" >> >> // or equivalently, with type inferred from context >> luke[keyPath: '.friends[0].name'] // "Han Solo" >> >> // [SE-0042][SR-3550] Unapplied method references >> 'String.lowercased()' // (String) -> String >> 'String.lowercased(with:)' // (String, Locale?) -> String >> >> Unlike the Lisp-style backtick, an apostrophe would appear on *both* ends of >> the key path (or method reference). > > For what it’s worth, I much rather prefer this approach and was going to > suggest it today. In Objective-C, keypaths were just strings so by using a > single tick, they still look *almost* like strings, but now they’re safe and > checked by the compiler - magical. > > l8r > Sean > > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution