Collections
Use arrays, dictionaries and sets with map, filter and reduce.
What you will be able to do
- Use arrays for ordered data.
- Use dictionaries for keyed lookups.
- Use sets for membership.
- Prefer map and filter over manual loops.
In plain English
Arrays keep order, dictionaries map keys to values and sets hold unique values. Value semantics mean assignment copies the collection. Use map, filter, reduce and sorted for transformations.
let lessons = ["HTML", "CSS", "SQL"]
let long = lessons.filter { $0.count >= 3 }
let lengths = lessons.map(\.count)
let total = lengths.reduce(0, +)
print(long, total)Your turn
EasyFilter a collection
Return only lessons whose name has at least three characters.
SWIFT · starter
lessonsCheck your understanding before moving on.
Knowledge checkQuestion 1
Which collection stores unique values without order?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.