Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 2: Closures

16. Challenge: Closures & Collections

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 15. compactMap & flatMap Next episode: 17. filter, reduce, & sort

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: 16. Challenge: Closures & Collections

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.

I’ve got another challenge for you! This time you’ll try out using forEach, map, compactMap, and flatMap on your own.

students.forEach
students.forEach { (<#Student#>) in
  <#code#>
}
students.forEach { (student) in
student.earnExtraCredit()
let classLibraryBooks = 
let classLibraryBooks = students.map { (<#Student#>) -> T in
  <#code#>
}
students.map { (student)
-> [String]
student.libraryBooks
print(classLibraryBooks)
let classPets = 
students.compactMap {...
{ (student) -> String? in
student.pet
{ ❌(student) -> String? in❌
  $0.pet
}
classLibraryBooks.flatMap { $0 }
let classLibraryBooks = students.map { (student) -> [String] in
  student.libraryBooks
}
print(classLibraryBooks)
let classLibraryBooks = students.flatMap