[swift-evolution] [Pitch] Property reflection
pgwsmith at gmail.com
Fri May 27 09:08:28 CDT 2016
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.
> On 27 May 2016, at 11:30 PM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution