> On Apr 3, 2017, at 1:47 PM, Joshua Alvarado via swift-evolution 
> <[email protected]> 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

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to