Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Alex-Christian Lazau
Alex-Christian Lazau
10,930 Points

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.