Programming in Swift: Fundamentals

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

Part 5: Functions & Named Types

38. Structures

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

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: 38. Structures

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

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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