Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 1: Functions

4. Overloading

Lesson Complete

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

See course reviews

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 3. Challenge: Functions Next episode: 5. Advanced Parameters

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials 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 the previous episode, we reviewed several functions that shared the same name. When you create multiple functions with the same name, it’s called “Overloading”.

func getPassStatus(for grade: Int) -> Bool {
  grade >= passingGrade
}
func getPassStatus(for grade: Int, lowestPass: Int ) -> Bool {
  grade >= lowestPass
}
getPassStatus(for: ozmaGrade, lowestPass: 88)
getPassStatus(for: jessyGrade)
func getPassStatus(for grade: Int, lowestPass: Int = passingGrade ) -> Bool {
  grade >= lowestPass
}
func getPassStatus
  
}
func getPassStatus(for grades: [Int]) -> Bool {
  
}
func getPassStatus(for grades: [Int]) -> Bool {
  var totalGrade = 0
  for grade in grades {
    totalGrade += grade
  }
}
  let averageGrade = totalGrade / grades.count
}
  return averageGrade >= passingGrade
}
getPassStatus(for: ozmaAllGrades)
stride(from: 10, to: 0, by: -2)
for i in stride(from: 10, to: 0, by: -2) {
  print(i)
}
for i in stride(from: 10, through: 0, by: -2) {
  print(i)
}
func getValue() -> Int {
  return 13
}
func getValue() -> String {
  "meow"
}
let value = getValue()
let intValue: Int = getValue()