πPre-lecture Reading I
SP 2026 | Zain Bilal
Before we build screens, we need to understand how iOS structures its code.
1. Classes and Objects
Classes: Think of a class as a blueprint for something. Each class contains properties and functions (methods) that determine its behavior and state. For example, a
Studentclass might have properties likename,age, andmajor. Notice that the properties have types:nameandmajorare strings, andageis an int.
We might represent this as: name: String, age: Int, major: String.
Objects: Think of objects as instances of the class. If a class is a blueprint for a house, an object is a house. To go with the student example above, an object would be:
name = "Asen",age = 38,major = "sleep". Basically, an object is a specific instance of a class with concrete values for its properties.Simple sentence to remember: Classes are blueprints that define the properties and behaviors something can have. (a cat has a number representing age and a string representing a name), Objects are the actual things (a cat with age 6 and name Jiwon)
2. Inheritance
We use classes and inheritance to avoid repeating ourselves when objects share common features. Imagine creating 100 human characters, instead of coding their basic traits 100 separate times, we can use a shared blueprint to do the heavy lifting.
Look at the photo below:
Both planes and submarines are vehicles that share some properties (Speed, NumberOfSeats...). However, a plane has a property that neither vehicle nor submarine share, Elevation. Similarly, a submarine might have a property that others do not, such as oxygenLeft. All the statements below are true:
Vehicle is a superclass of both Submarine and Plane.
Submarine and Plane inherit Vehicle.
Submarine and Plane are subclasses of Vehicle.
How does this tie into UIKit?
UIKit provides a massive library of pre-built classes we ca use. For example, if you want text on your screen, you use the UILabel class. If you want a button, you use the UIButton class.
More importantly, when we create a new screen (or "page") in our app, we don't code the underlying mechanics from scratch. Instead, we create a subclass of a master (superclass) UIKit class called UIViewController. This means our custom page automatically inherits all the complex, behind-the-scenes behaviors of a standard iOS screen. All we have to do is write the code to add our specific properties, like text, images, and buttons, on top of it!
Last updated
Was this helpful?