> For the complete documentation index, see [llms.txt](https://ios-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-course.cornellappdev.com/course-content/week-2-or-uikit-mvc-and-control/pre-lecture-reading-i.md).

# Pre-lecture Reading I

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 `Student` class might have properties like `name`, `age`, and `major`.  Notice that the properties have types: `name` and `major` are strings, and `age` is an int.&#x20;

{% hint style="info" %}
&#x20;We might represent this as: `name: String`, `age: Int`, `major: String.`
{% endhint %}

* 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)

<figure><img src="/files/ItGtWWhLz9pYTdJTJzEn" alt=""><figcaption></figcaption></figure>

### 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:

<figure><img src="/files/nGIxkCiL6TSUjbJTfjR8" alt=""><figcaption></figcaption></figure>

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 can 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!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ios-course.cornellappdev.com/course-content/week-2-or-uikit-mvc-and-control/pre-lecture-reading-i.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
