count
The number of elements in the array.
var count: Int { get }
The number of elements in the array.
var count: Int { get }
import Swift
@frozen struct Array<Element>
An ordered, random-access collection.
@frozen struct Int
A signed integer value type.
init()
Creates a new, empty array.
init<S>(_ s: S) where Element == S.Element, S : Sequence
Creates an array containing the elements of a sequence.
init(arrayLiteral elements: Element...)
Creates an array from the given array literal.
init(repeating repeatedValue: Element, count: Int)
Creates a new array containing the specified number of a single, repeated value.
init(unsafeUninitializedCapacity: Int, initializingWith initializer: (inout UnsafeMutableBufferPointer<Element>, inout Int) throws -> Void) rethrows
Creates an array with the specified capacity, then calls the given closure with a buffer covering the array’s uninitialized memory.
var capacity: Int { get }
The total number of elements that the array can contain without allocating new storage.
var customMirror: Mirror { get }
A mirror that reflects the array.
var debugDescription: String { get }
A textual representation of the array and its elements, suitable for debugging.
var description: String { get }
A textual representation of the array and its elements.
var endIndex: Int { get }
The array’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var startIndex: Int { get }
The position of the first element in a nonempty array.
subscript(bounds: Range<Int>) -> ArraySlice<Element> { get set }
Accesses a contiguous subrange of the array’s elements.
subscript(index: Int) -> Element { get set }
Accesses the element at the specified position.
static func + (lhs: Array<Element>, rhs: Array<Element>) -> Array<Element>
static func += (lhs: inout Array<Element>, rhs: Array<Element>)
mutating func append(_ newElement: Element)
Adds a new element at the end of the array.
mutating func append<S>(contentsOf newElements: S) where Element == S.Element, S : Sequence
Adds the elements of a sequence to the end of the array.
func distance(from start: Int, to end: Int) -> Int
Returns the distance between two indices.
func formIndex(after i: inout Int)
func formIndex(before i: inout Int)
func index(_ i: Int, offsetBy distance: Int) -> Int
Returns an index that is the specified distance from the given index.
func index(_ i: Int, offsetBy distance: Int, limitedBy limit: Int) -> Int?
Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func index(after i: Int) -> Int
Returns the position immediately after the given index.
func index(before i: Int) -> Int
Returns the position immediately before the given index.
mutating func insert(_ newElement: Element, at i: Int)
Inserts a new element at the specified position.
@discardableResult mutating func remove(at index: Int) -> Element
Removes and returns the element at the specified position.
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
Removes all elements from the array.
mutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where Element == C.Element, C : Collection
Replaces a range of elements with the elements in the specified collection.
mutating func reserveCapacity(_ minimumCapacity: Int)
Reserves enough space to store the specified number of elements.
mutating func withContiguousMutableStorageIfAvailable<R>(_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R) rethrows -> R?
func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R?
func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R
Calls a closure with a pointer to the array’s contiguous storage.
func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R
Calls the given closure with a pointer to the underlying bytes of the array’s contiguous storage.
mutating func withUnsafeMutableBufferPointer<R>(_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R) rethrows -> R
Calls the given closure with a pointer to the array’s mutable contiguous storage.
mutating func withUnsafeMutableBytes<R>(_ body: (UnsafeMutableRawBufferPointer) throws -> R) rethrows -> R
Calls the given closure with a pointer to the underlying bytes of the array’s mutable contiguous storage.
typealias Index = Int
The index type for arrays, Int
.
typealias Indices = Range<Int>
The type that represents the indices that are valid for subscripting an array, in ascending order.
typealias Iterator = IndexingIterator<Array<Element>>
The type that allows iteration over an array’s elements.