100 Days of SwiftUI
2026-04-29
Looks like it’s going to be a very full Day 12. I’m in the flailing part now. I think it will be easier once we’re actually doing something. FLW*

Classes
just because a feature exists, it doesn’t mean you need to use it
- SwiftUI uses structs for UI design and classes for data
How to create your own classes
- Classes have some similarities to structs (e.g. creating, properties and methods, custom inits)
- Main differences
- Inheritance — make one class build on the components of another class
- Initializer — required to make your own (or use defaults)
- Copies — a copy of an instance of a class has the same data as the original instance. Change data in one, it changes them all
- Deinialize — used to free up reserved resources when the last instance is destroyed
- Constant class instances can have their variable properties changed
SwiftUI uses the Copies functionality a lot.
When you choose a class over a struct you’re doing so because you want one of the above behaviors
How to make one class inherit from
- Terminology: parent/child or super/subclass
- Syntax:
Developer: Employee—child: parent - child can use parent methods, and can also have their own version of it using the
overridekeyword. Sometimes you don’t need theoverridekeyword because of course you don’t. finalkeyword will stop the inheritance path
How to add initializers for classes
- child classes must initialize its properties (if it has them) before it calls the parent’s initializer
- call the parent’s initializer using
super.init(...) superisn’t just for initializers- if the child doesn’t have any initializers then it automatically inherits from its parent
How to copy classes
- classes are reference types — they all refer to the same data
- “It might seem like a bug, but it’s really a feature” when showing that 2 copies of an instance share the same data
- structs do not share data, so changing the copy doesn’t change the original instance
- you have to do some machinations to make independent instances from a copy of a class
How to create a deinitializer for a class
deinitused within the class structure, no parentheses (init(...) {}vsdeinit {})- optional
- don’t take parameters or return data
- aren’t called directly (only by the system)
- something something scope (the context in which things exist)
How to work with variables inside classes
if a property of a class is variable, even a constant instance can change that variable. The pointer is going to the same location in memory, but the content of that location has changed. The instance still exists.
Given this example there are four options:

class User {
var _or let_ name = "Paul"
}
let _or var_ user = User()
user.name = "Taylor"
print(user.name)- Constant instance, constant property – a signpost that always points to the same user, who always has the same name.
- Constant instance, variable property – a signpost that always points to the same user, but their name can change.
- Variable instance, constant property – a signpost that can point to different users, but their names never change.
- Variable instance, variable property – a signpost that can point to different users, and those users can also change their names.
Quizzes
- Creating your own classes — 9/12
- Class inheritance — 10/12
- Copying objects — 10/12 Frakkin’
structvsclass - Deinitializers — 10/12
- Mutability — 10/12
Checkpoint 7
Your challenge is this: make a class hierarchy for animals, starting with Animal at the top, then Dog and Cat as subclasses, then Corgi and Poodle as subclasses of Dog, and Persian and Lion as subclasses of Cat.
But there’s more:
- The
Animalclass should have a legs integer property that tracks how many legs the animal has. - The
Dogclass should have aspeak()method that prints a generic dog barking string, but each of the subclasses should print something slightly different. - The
Catclass should have a matchingspeak()method, again with each subclass printing something different. - The
Catclass should have anisTameBoolean property, provided using an initializer.
I haven’t been able to complete this challenge yet. I really don’t understand where parameters go. Here is my evidence:

I’ll come back to this another day.
Footnotes
Famous Last Words ↩︎