[swift-evolution] [Review] SE-0161: Smart KeyPaths: Better Key-Value Coding for Swift
Joe Groff
jgroff at apple.com
Mon Apr 3 16:22:39 CDT 2017
> On Apr 3, 2017, at 1:47 PM, Joshua Alvarado via swift-evolution <swift-evolution at swift.org> wrote:
>
> Quesition about this proposal. Will it be possibly to create an array of keyPaths and set an objects value with enumeration.
>
> Example:
> struct Foo {
> var firstName: String
> var lastName: String
> }
>
> let keyPaths = [#keyPath(.firstName), #keyPath(.lastName)]
>
> for key in keyPaths {
> foo[keyPath: key] = "bar"
> }
>
> print(foo) // firstName = bar, lastName = bar
If you happen to have an already-initialized value `foo`, yes, but you wouldn't be able to initialize a value this way. That would require knowing that some assigning to some set of key paths will fully initialize a value. That's something we'd like to support in some way eventually, but not as part of this first proposal.
-Joe
More information about the swift-evolution
mailing list