Instance Property
インスタンスプロパティ
last
The last element of the collection.
コレクションの最後の要素。
Technology
- Swift Standard Library
Swift標準ライブラリ
Declaration
宣言
var last: Elements.Index
? { get }
Available when Elements
conforms to BidirectionalCollection
.
Elements
がBidirectionalCollection
に準拠する時に利用可能です。
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)
}
Complexity: O(1)
計算量:O(1)