Junior — Middle
Can you list different types of collections used in Swift?
sobes.tech AI
Answer from AI
In Swift, the main collection types:
- Array — an ordered list of elements of the same type.
- Set — an unordered collection of unique elements.
- Dictionary — a collection of key-value pairs.
Example usage:
var numbers: [Int] = [1, 2, 3]
var uniqueNames: Set<String> = ["Anna", "Bob", "Anna"] // contains "Anna" and "Bob"
var userInfo: [String: String] = ["name": "Ivan", "city": "Moscow"]