last
The last element of the collection.
var last: Self.Element? { get }
If the collection is empty, the value of this property is nil
.
let numbers = [10, 20, 30, 40, 50]
if let lastNumber = numbers.last {
print(lastNumber)
}
// Prints "50"
The last element of the collection.
var last: Self.Element? { get }
If the collection is empty, the value of this property is nil
.
let numbers = [10, 20, 30, 40, 50]
if let lastNumber = numbers.last {
print(lastNumber)
}
// Prints "50"
import Swift
protocol BidirectionalCollection<Element> : Collection where Self.Indices : BidirectionalCollection, Self.SubSequence : BidirectionalCollection
A collection that supports backward as well as forward traversal.
associatedtype Element where Self.Element == Self.Iterator.Element
A type representing the sequence’s elements.
func difference<C>(from other: C, by areEquivalent: (C.Element, Self.Element) -> Bool) -> CollectionDifference<Self.Element> where C : BidirectionalCollection, Self.Element == C.Element
Returns the difference needed to produce this collection’s ordered elements from the given collection, using the given predicate as an equivalence test.
func distance(from start: Self.Index, to end: Self.Index) -> Int
func dropLast(_ k: Int) -> Self.SubSequence
Returns a subsequence containing all but the specified number of final elements.
func formIndex(before i: inout Self.Index)
func index(_ i: Self.Index, offsetBy distance: Int) -> Self.Index
func index(_ i: Self.Index, offsetBy distance: Int, limitedBy limit: Self.Index) -> Self.Index?
func last(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the last element of the sequence that satisfies the given predicate.
func lastIndex(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Index?
Returns the index of the last element in the collection that matches the given predicate.
func reversed() -> ReversedCollection<Self>
Returns a view presenting the elements of the collection in reverse order.
func suffix(_ maxLength: Int) -> Self.SubSequence
Returns a subsequence, up to the given maximum length, containing the final elements of the collection.