Almost all Swift applications will be object oriented. Chapter 1, Exploring Swift, and Chapter 2, Playing with Swift, both demonstrated functional and procedural Swift code. Classes such as
Process from the
CoreFoundation framework, and
UIImage from the
UIKit framework were used to demonstrate how classes can be used in applications. This section describes how to create classes, protocols, and enums in Swift.
A class is created in Swift using the
class keyword and braces are used to enclose the class body. The body can contain variables called properties as well as functions called methods, which are collectively referred to as members. Instance members are unique to each instance, ...