Protocols and SuperClass In Swift 2.0

In one of the WWDC15 session videos, it made mention of Swift as a POP language.

In Swift 2.0 there the notion of using "extensions" to entend types(class, struct enum).

Here's the situation.

I have a hierachy of classes with one superclass.

That class has an init() method that subclass calls

Since it's a superclass, I do not want it being instantiated.


If I can be directed to some code examples or even a discussion on the subject, that would be great.

Thanks!

Answered by Jens in 10673022

Extending classes, structs and enums was possible even before Swift 2, the new thing is protocol extensions.


Resources:

https://developer.apple.com/swift/resources/


Read the whole of The Swift Programming Language (it's also available as an iBook, make sure you get the prerelease version that is about Swift 2).

And then re-read the section on protocols (incliding protocol extensions) in Swift Programming Language:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID267

Accepted Answer

Extending classes, structs and enums was possible even before Swift 2, the new thing is protocol extensions.


Resources:

https://developer.apple.com/swift/resources/


Read the whole of The Swift Programming Language (it's also available as an iBook, make sure you get the prerelease version that is about Swift 2).

And then re-read the section on protocols (incliding protocol extensions) in Swift Programming Language:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID267

Thanks for the link. Now i know that i can have init() methods in a protocol.

Protocols and SuperClass In Swift 2.0
 
 
Q