0
0
iOS Swiftmobile~5 mins

Collections (Array, Dictionary, Set) in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an Array in Swift?
An Array is an ordered collection of values. You can access elements by their position (index). Arrays keep the order of items.
Click to reveal answer
beginner
How does a Dictionary work in Swift?
A Dictionary stores key-value pairs. Each key is unique and maps to a value. You use the key to find the value quickly.
Click to reveal answer
beginner
What is a Set in Swift and when to use it?
A Set is an unordered collection of unique values. Use it when you want to store items without duplicates and order does not matter.
Click to reveal answer
beginner
How do you add an element to a Swift Array?
Use the append() method. For example: myArray.append(5) adds the number 5 to the end of the array.
Click to reveal answer
beginner
How do you check if a Set contains a value in Swift?
Use the contains() method. For example: mySet.contains(3) returns true if 3 is in the set, otherwise false.
Click to reveal answer
Which Swift collection type keeps elements in order and allows duplicates?
ATuple
BDictionary
CSet
DArray
How do you access a value in a Dictionary?
ABy key
BBy value
CBy position
DBy index number
What happens if you add a duplicate element to a Set?
AIt adds the duplicate
BIt ignores the duplicate
CIt replaces the old element
DIt causes an error
Which method adds an element to the end of an Array?
Aappend()
Binsert()
Cadd()
Dpush()
Which collection type is best to store unique items without caring about order?
AArray
BDictionary
CSet
DString
Explain the differences between Array, Dictionary, and Set in Swift.
Think about order, uniqueness, and how you access elements.
You got /3 concepts.
    Describe a real-life example where you would use a Set instead of an Array.
    Imagine a guest list where each person should appear only once.
    You got /3 concepts.