Instance Property インスタンスプロパティ

last

The last element of the collection. コレクションの最後の要素。

Declaration 宣言

var last: Base.Element? { get }

Discussion 解説

If the collection is empty, the value of this property is nil. コレクションが空であるならば、このプロパティはnilです。


let numbers = [10, 20, 30, 40, 50]
if let lastNumber = numbers.last {
    print(lastNumber)
}
// Prints "50"

Complexity: O(1) 計算量:O(1)