/// The first element of the collection.
///
/// If the collection is empty, the value of this property is `nil`.
///
/// - Complexity: O(1)
@inlinable public var first: Element? { get }
let numbers = [10, 20, 30, 40, 50]
if let firstNumber = numbers.first {
print(firstNumber)
}
// Log: 10
/// The last element of the collection.
///
/// If the collection is empty, the value of this property is `nil`.
///
/// - Complexity: O(1)
@inlinable public var last: Element? { get }
let numbers = [10, 20, 30, 40, 50]
if let lastNumber = numbers.last {
print(lastNumber)
}
// Log: 50
网友评论