Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 2: Closures

13. Challenge: Closure Syntax

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: 12. Closure Syntax Next episode: 14. forEach & map

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.

It is challenge time again! You’ll find it on page 5 of the Playground for this part of the course. Pause the video, practice writing closures a few different ways, and then come back to check your work!

let copyLines😺_2🛑 =
let copyLines_2😺: (String, Int) -> Void🛑 = 
let copyLines_2: (String, Int) -> Void = { (offense❌: String❌, repeatCount❌: Int❌) -> Void in
 = { ❌(❌offense, repeatCount❌)❌ -> Void in
let copyLines_3:
 = { offense, repeatCount❌ -> Void❌ in
let copyLines_4: 
= { ❌offense, repeatCount❌ in
  print( String(repeating: "I must not \(😺$0).", count: 😺$1) )
copyLines("tell lies", 5)
copyLines_2("tell lies", 5)
copyLines_3("tell lies", 5)
copyLines_4("tell lies", 5)