[swift-evolution] Proposal - Allow properties in Extensions

Joe Groff jgroff at apple.com
Fri Dec 18 17:15:38 CST 2015


> On Dec 18, 2015, at 12:49 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> I only see the benefits on this.
>> 	• We don't have to store all states in one file. States can be stored separately. So, we can write code in more composition style.
>> 	• We can add new states to the existing type. Not just NSObject subclass with associated object.
> 
> I think people generally want this; the question is how to implement it, and especially how to implement it *without* either limiting it to types in the same module, or dangling what amounts to a dictionary off every single object and struct. (Structs are more difficult than objects, because they don’t have stable identities.) Any ideas?

You could say that types whose conformance to the protocol lives in the same module as the type itself get the default property storage, but external extensions that introduce the conformance can't use the default stored property and have to supply their own implementation.

-Joe


More information about the swift-evolution mailing list