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 ...

Get Swift Translation Guide for Objective-C Users: Develop and Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.