Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

38. Structures

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: 37. Challenge: Functions Next episode: 39. Challenge: Structures

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.

In this exercise, we’ll begin our tour of structures in Swift. You’ll usually hear them called “Structs”.

struct Student {
  
}
let name: String
var grade: Int
var pet: String?
Student
Student(name: "Chris", grade: 49, pet: "Mango")
let chris = ...
let sam = Student(name: "Sam", grade: 99, pet: nil)
let catie = Student(name: "Catie", grade: 75, pet: "Ozma")
func getPassStatus(
func getPassStatus(lowestPass: Int = 50) -> Bool {
  grade >= lowestPass
}
func getPassStatus(lowestPass: Int = 50) -> Bool {
  grade >= lowestPass
}
func getPassStatus(lowestPass: Int = 50) -> Bool {
  grade >= lowestPass
}
chris.
chris.getPassStatus()
func earnExtraCredit() {
  grade += 10
}
mutating func earnExtraCredit...
chris.earnExtraCredit()
var chris = Student...
chris.getPassStatus()
let evilCatie
let evilCatie = catie
evilCatie.grade = 100
evilCatie.pet = "Mustachioed Ozma"
var evilCatie = catie
catie
evilCatie