Here’s an idea using enums. They work similar to a lens, where they are 
separate from the actual instance. So you can convert string keys or validate 
potential values without needing an instance.

The PropertyIdentifierProtocol is implemented by an string representable enum, 
piggy backing on its failable initializer for converting from strings.
The PropertyStateProtocol, implemented by an enum with associated values, 
encapsulates a property in a type-safe manner, allowing it to be extracted as 
an entity then applied to other instances. It has a failable initializer for 
validating a value.

https://gist.github.com/BurntCaramel/315ee4dfca0c240755b534e1a5ee183f


> On 27 May 2016, at 11:30 PM, Matthew Johnson via swift-evolution 
> <[email protected]> wrote:
> 
> Property descriptors could be useful in the sense that they wouldn't need to 
> refer back to the instance.  But I would also like to see a way to get 
> something like a lens into the property for a specific instance which is what 
> the views allow for.  This design doesn't allow for that.  Maybe we want to 
> allow you to query for property descriptors alone, lenses alone, or the 
> combination in a view.

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

Reply via email to