Tsallaka zuwa abun ciki
Justice Tech School

Swift Classes

A class is a reference type that supports inheritance. Initialisers use init. Several variables can point to the same instance.

Example
class Student {
    var name: String
    var score = 0
    init(name: String) { self.name = name }
    func describe() -> String { "\(name): \(score)" }
}
let s = Student(name: "Ada")
let t = s
t.score = 90
print(s.describe())

Exercise

Initializer name.

(name: String) {}

Quiz Test

What happens when you assign a class instance?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.