Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Protocols in Swift Protocol Basics Modeling Behavior With Protocols

jungwook ryu
jungwook ryu
4,004 Points

Does Swift not have abstract class?

I have some experiences with Java. so I think that your example is appropriate to use abstract class than Interface. (In Java) abstract class Employee { abstract void pay(); } Does Swift not have the concept like "abstract class" of Java?

Duncan Hall
Duncan Hall
6,417 Points

So, if we wanted to make sure that all Employees implement Payable, what would we do?

3 Answers

For anyone who reads this question: Swift does not have abstract classes. I recommend changing your programming paradigms when working with Swift. Instead of embracing classes and inheritance, Swift delivers its full power when working with value types and composition. Here is a great WWDC session concerning this topic: https://developer.apple.com/videos/play/wwdc2015/408/

Paolo Scamardella
Paolo Scamardella
24,828 Points

As far as I know, there is no abstract classes in Swift.

Trevor Duersch
Trevor Duersch
9,964 Points

Sounds similar to implementing a protocol. Then if you want to take it a bit further, you can do extensions on the protocols to get the patterns of abstract classes. Do a google search and you can probably find more information.