Programming in Swift: Fundamentals

Oct 19 2021 · Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

40. Classes

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 39. Challenge: Structures Next episode: 41. Challenge: Classes

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 40. Classes

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Classes are a lot like Structures. They have properties, methods, and initializers. However, Classes are reference types, instead of value types. In this part of the episode, you’ll get an idea of how that affects your code.

struct Actor {
  let name: String
  var filmography: [String] = []
}
Actor(name: "Zoe Saldana", filmography: ["<#T##[String]#>"])
 …"Guardians of the Galaxy"])
var gotgStar = Actor(…
gotgStar.filmography.append("Avatar")
var starTrekStar = gotgStar
starTrekStar.filmography.append("Star Trek")
func signOnForSequel(franchiseName: String) {
    
}
mutating …
filmography.append("Upcoming \(franchiseName) sequel")
var avatarStar = starTrekStar
for franchiseName in avatarStar.filmography {
  avatarStar.signOnForSequel(franchiseName: franchiseName)
}
avatarStar.filmography
starTrekStar.filmography
gotgStar.filmography
class Actor {
init
init(name: String, filmography: [String]) {

}
init(name: String, filmography: [String]) {
    self.name = name
    self.name = name
    self.filmography = filmography
}
❌mutating❌ func…
let gotgStar …
…

let starTrekStar …
avatarStar.filmography
starTrekStar.filmography
gotgStar.filmography