Swift: ``` // Array: Swift's default collection, w...
# language-proposals
b
Swift:
Copy code
// Array: Swift's default collection, which can be truly immutable.
let array0: Array<Int> = Array<Int>(arrayLiteral: 1, 2, 3) // Basis: The most explicit syntax for creating an array, by sending varargs of values
let array1 = [1, 2, 3] // Array is the default collection type in Swift, so without specifying a type, you create an array with bracket syntax alone
let array2: Array<Int> = [1, 2, 3] // Of course, you can also specify the type. Useful if you want to use a supertype
let array3: [Int] = [1, 2, 3] // P.S. I love the [Type] syntax for declaring a collection

// Set: A simple implementation of a set of values without duplicates or order
let set: Set<Int> = [1, 2, 3] // Swift knows you are creating a set here with bracket syntax
functionThatTakesASet([4, 5, 6]) // Swift passes this as a set, just as you'd expect

// Dictionary: Swift's default map
let dictionary0: Dictionary<String, Int> = Dictionary<String, Int>(dictionaryLiteral: ("a", 1), ("b", 2)) // Basis: The most explicit syntax for creating a dictionary, by sending varargs of tuples representing keys and values
let dictionary1 = ["a": 1, "b": 2] // Since Dictionary is Swift's default map, no typing is required
let dictionary2: Dictionary<String, Int> = ["a": 1, "b": 2] // Of course, you can also specify the type. Useful if you want to use a supertype
let dictionary3: [String: Int] = ["a": 1, "b": 2] // P.P.S. I also love the [TypeA: TypeB] syntax for creating a map