O'Reilly logo

Swift Translation Guide for Objective-C Users: Develop and Design by Maurice Kelly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Classes

Swift is an object-oriented programming (OOP) language, just like Objective-C. The defining principles of OOP are inheritance, polymorphism, and encapsulation, and all these principles are implemented in Swift by the class.

Creating Classes

To define a class in Objective-C required two files (one for the header and one for the implementation) and special keywords in the files to indicate where the @interface and @implementation sections should go.

Swift simplifies the definition of a class by requiring the keyword class, followed by the class name and a set of curly braces, and only has to be created in one file:

Swift

class VolumeControl {}

That is all it takes to create a class. You can instantiate it by calling the empty ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required