[swift-evolution] Proposal - Allow properties in Extensions

Kevin Kachikian kevyk at mac.com
Tue Dec 8 12:51:46 CST 2015

I’d like to proposal to the Swift community and discuss the advantages and disadvantages of adding modifiable properties to extensions (in addition to the already existing computed properties, instance methods, subscripts, etc.):

extension SomeType {
	var aNewProperty: Int
	var anotherVariable: String
	var aThirdOne: MyStruct



I have experienced many occasions where adding a a property to an extension would have resulted in cleaner code by keeping all similar code locally together in a file. Not knowing much about language design, I don't know if this offering this might break some fundamental principal in OOP design. Curiously ObjC also had this limitation but apparently C# offers the capability in partial classes.

One such use case is when extending ones own code, it's nice to break similar code blocks/behavior into their own extensions sometimes requiring the addition of properties. It would be nice to provide those properties right in line with the new code instead of just having a bunch of properties forced at the top of a main class file.

Wha-da-ya’all think?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151208/2410e68b/attachment.html>

More information about the swift-evolution mailing list