Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

35. Introduction to Functions

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: 34. Introduction Next episode: 36. Functions & Return

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.

Functions are a core part of many programming languages. Simply put, a function lets you define a reusable block of code that performs a task.

func
func printHello()
func printHello() {

}
func printHello() {
  print("Hello!")
}
printHello()
printHello()
printHello()
let chrisPassed = chrisGrade >= passingGrade
let samPassed = samGrade >= passingGrade
func printPassStatus
func printPassStatus() {

}
func printPassStatus(grade: Int) {...
grade * 2
  ❌  grade * 2
  print(grade >= passingGrade)
  print(grade >= passingGrade ? "You passed!" : "Keep studying.")
printPassStatus(grade: samGrade)
func printPassStatus(grade: Int😺, lowestPass: Int🛑) {...
  print(grade >= 😺lowestPass🛑 ? "You passed!" : "Keep studying.")
printPassStatus(for: samGrade😺, lowestPass: 80🛑)
func printPassStatus(grade: Int, lowestPass: Int 😺= passingGrade🛑) {...
printPassStatus(grade: chrisGrade)
func printHighestGrade(grade1: Int, grade2: Int) {
  print(grade1 >= grade2 ? grade1 : grade2)
}
printHighestGrade(grade1: chrisGrade, grade2: samGrade)
func printHighestGrade(😺_ grade1: Int, 😺_ grade2: Int) {
printHighestGrade(chrisGrade, samGrade)
func printPassStatus(😺for 🛑grade: Int, lowestPass: Int = passingGrade) {...
printPassStatus(😺for🛑: samGrade, lowestPass: 80)
printPassStatus(😺for🛑: chrisGrade)