[swift-evolution] [Proposal] Property behaviors

Joe Groff jgroff at apple.com
Thu Jan 14 12:44:24 CST 2016


> On Jan 14, 2016, at 10:33 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> That parameterization could be achieved, somewhat more verbosely, using an accessor 'key { return "id" }'. If behaviors could be parameterized in-line, I wouldn't do it by passing the params to `init`, since that again imposes the need for per-instance storage to carry `key` from the behavior initialization to the property implementation.

Thinking about this more, maybe the need for instance storage could be avoided by letting behaviors declare `static` properties. It's likely that behavior instantiations will need some global data structure, at least in debug builds, to collect their parameterizations from property decls using the behavior. It'd make sense to put some of that global structure under the behavior's control. We'd still potentially need a separate `static init()` to initialize that storage once per declaration, rather than once per instance.

This particular use case for mapped serialization/deserialization is interesting. A potential future extension to better support it might be to let behaviors optionally bind the name of a property using them as a `String` (or other `StringLiteralConvertible` type).

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160114/d497b320/attachment.html>


More information about the swift-evolution mailing list