[swift-evolution] stored properties in extensions (was: associated objects)

Charles Srstka cocoadev at charlessoft.com
Sun Oct 9 15:45:16 CDT 2016


*Replace both instances of “class C: P” with just “class C” since the conformance comes in the extension. That’s what I get for writing this quickly.

Charles

> On Oct 9, 2016, at 3:43 PM, Charles Srstka <cocoadev at charlessoft.com> wrote:
> 
> protocol P {
> 	var foo: String { get }
> 	func bar()
> }
> 
> protocol Q {
> 	var baz: Int { get }
> 	func qux()
> }
> 
> class C: P {
> 	var foo: String // <- what is this doing here?
> 	var baz: Int // <- ditto
> }
> 
> extension C: P {
> 	func bar() {}
> }
> 
> extension C: Q {
> 	func qux() {}
> }
> 
> we could simply:
> 
> protocol P {
> 	var foo: String { get }
> 	func bar()
> }
> 
> class C: P {}
> 
> extension C: P {
> 	var foo: String
> 	func bar() {}
> }
> 
> extension C: Q {
> 	var baz: Int
> 	func qux() {}
> }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161009/8278fdde/attachment.html>


More information about the swift-evolution mailing list