Introduction
Array is an ordered, random-access collection type. Arrays are one of the most commonly used data types in an app. We use the Array type to hold elements of a single type, the array's Element type. An array can store any kind of elements---from integers to strings to classes.
Syntax
- Array<Element> // The type of an array with elements of type Element
- [Element] // Syntactic sugar for the type of an array with elements of type Element
- [element0, element1, element2, ... elementN] // An array literal
- [Element]() // Creates a new empty array of type [Element]
- Array(count:repeatedValue:) // Creates an array of
count
elements, each initialized to repeatedValue
- Array(_:) // Creates an array from an arbitrary sequence
Arrays are an ordered collection of values. Values may repeat but must be of the same type.