Programming in Swift: Fundamentals

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

Part 5: Functions & Named Types

36. Functions & Return

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 35. Introduction to Functions Next episode: 37. Challenge: Functions

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

If you followed along and built the Bullseye app, you might remember writing functions like amountOff or sliderValueRounded. Both of those methods returned a value. When a function or method returns a value, once the function is called that value can be stored or used in-place.

func amountOff() -> Int {
  abs(target - sliderValueRounded())
func pointsForCurrentRound() -> Int {
  let maximumScore = 100
  let difference = amountOff()
  let bonus: Int
    if difference == 0 {
      bonus = 100
    } else if difference == 1 {....
func sliderValueRounded() -> Int {

func amountOff() -> Int {
  abs(target - sliderValueRounded())
...) -> {...
...) -> Bool {... 
  return grade >= lowestPass
grade >= lowestPass
func getPassStatus
let chrisPassStatus = getPassStatus(for: chris.grade)
let samPassStatus = getPassStatus(for: sam.grade)
let classPassStatus = getPassStatus(for: chris.grade) && getPassStatus(for: sam.grade)
let sam = (name: "Sam", grade: 99, pet: nil)
let sam: (name: String, grade: Int, pet: String?) = (name: "Sam", grade: 99, pet: nil)
typealias Student =
let chris: Student = (name: "Chris", grade: 49, pet: "Mango")
let sam: Student = (name: "Sam", grade: 99, pet: nil)
func orderPetCollar(for student: Student) {

guard let pet =
guard let pet = else { }
guard let pet = else { return }
print("One custom collar for \('s pet, \(pet)!")
orderPetCollar(for: chris)
orderPetCollar(for: sam)