Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 2: Closures

11. Challenge: Closures

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: 10. Closures Next episode: 12. Closure Syntax

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.

I’ve got a quick challenge to help you practice writing closures. You’ll find it on page 3 of the Playground for this part of the course. Pause the video, give it a try, and then come back to go over some solutions. Have fun!

let fullName =
let fullName = {

}
let fullName = { 😺(firstName: String, lastName: String?) -> String🛑 
}
let fullName = { (firstName: String, lastName: String?) -> String 😺in 
}
  😺firstName + " " + (lastName ?? "")🛑
let ozmaName = calculateFullName(firstName: "Ozma", lastName: "Catterwaul")
let princeName = fullName("Prince", nil)
printResult({ (<#Double#>, <#Double#>) -> Double in
  <#code#>
}, <#T##a: Double##Double#>, <#T##b: Double##Double#>)
printResult(
  { (😺a, b🛑) -> Double in
    ((a * a) + (b * b)).squareRoot()
  }
printResult(
  { (a, b) -> Double in
    ((a * a) + (b * b)).squareRoot()
  }, 
😺5, 3🛑
)