Instance Property (Default implementation)swift 6.0.1Swift
count
The number of elements in the collection.
var count: Int { get }
To check whether a collection is empty, use its isEmpty
property instead of comparing count
to zero. Unless the collection guarantees random-access performance, calculating count
can be an O(n) operation.
Implements
var count: Int
The number of elements in the collection.
Other members in extension
Typealiases
Show obsolete interfaces (1)
Hide obsolete interfaces
Instance members
var first: Self.Element?
The first element of the collection.
var isEmpty: Bool
A Boolean value indicating whether the collection is empty.
var underestimatedCount: Int
A value less than or equal to the number of elements in the collection.
subscript<R>(R
) -> Self.SubSequence Accesses the contiguous subrange of the collection’s elements specified by a range expression.
subscript((UnboundedRange_) -> ()
) -> Self.SubSequence subscript(RangeSet<Self.Index>
) -> DiscontiguousSlice<Self> Accesses a view of this collection with the elements at the given indices.
func distance(from: Self.Index, to: Self.Index
) -> Int Returns the distance between two indices.
func drop(while: (Self.Element) throws -> Bool
) rethrows -> Self.SubSequence Returns a subsequence by skipping elements while
predicate
returnstrue
and returning the remaining elements.func dropFirst(Int
) -> Self.SubSequence Returns a subsequence containing all but the given number of initial elements.
func dropLast(Int
) -> Self.SubSequence Returns a subsequence containing all but the specified number of final elements.
func firstIndex(where: (Self.Element) throws -> Bool
) rethrows -> Self.Index? Returns the first index in which an element of the collection satisfies the given predicate.
func formIndex(inout Self.Index, offsetBy: Int
) Offsets the given index by the specified distance.
func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index
) -> Bool Offsets the given index by the specified distance, or so that it equals the given limiting index.
func formIndex(after: inout Self.Index
) Replaces the given index with its successor.
func index(Self.Index, offsetBy: Int
) -> Self.Index Returns an index that is the specified distance from the given index.
func index(Self.Index, offsetBy: Int, limitedBy: Self.Index
) -> Self.Index? Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func indices(where: (Self.Element) throws -> Bool
) rethrows -> RangeSet<Self.Index> Returns the indices of all the elements that match the given predicate.
func map<T, E>((Self.Element)
throws Returns an array containing the results of mapping the given closure over the sequence’s elements.
func prefix(Int
) -> Self.SubSequence Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.
func prefix(through: Self.Index
) -> Self.SubSequence Returns a subsequence from the start of the collection through the specified position.
func prefix(upTo: Self.Index
) -> Self.SubSequence Returns a subsequence from the start of the collection up to, but not including, the specified position.
func prefix(while: (Self.Element) throws -> Bool
) rethrows -> Self.SubSequence Returns a subsequence containing the initial elements until
predicate
returnsfalse
and skipping the remaining elements.func randomElement(
) -> Self.Element? Returns a random element of the collection.
func randomElement<T>(using: inout T
) -> Self.Element? Returns a random element of the collection, using the given generator as a source for randomness.
func removingSubranges(RangeSet<Self.Index>
) -> DiscontiguousSlice<Self> Returns a collection of the elements in this collection that are not represented by the given range set.
func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Self.Element) throws -> Bool
) rethrows -> [Self.SubSequence] Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.
func suffix(Int
) -> Self.SubSequence Returns a subsequence, up to the given maximum length, containing the final elements of the collection.
func suffix(from: Self.Index
) -> Self.SubSequence Returns a subsequence from the specified position to the end of the collection.
Show obsolete interfaces (6)
Hide obsolete interfaces
func distance<T>(from: Self.Index, to: Self.Index
) -> T func flatMap((Self.Element) throws -> String?
) rethrows -> [String] func formIndex<T>(inout Self.Index, offsetBy: T
) func formIndex<T>(inout Self.Index, offsetBy: T, limitedBy: Self.Index
) -> Bool func index<T>(Self.Index, offsetBy: T
) -> Self.Index func index<T>(Self.Index, offsetBy: T, limitedBy: Self.Index
) -> Self.Index?