Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

40. Classes

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 39. Challenge: Structures Next episode: 41. Challenge: 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.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

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