Instance Property


The first element of the collection.


var first: Bound? { get }


If the collection is empty, the value of this property is nil.

let numbers = [10, 20, 30, 40, 50]
if let firstNumber = numbers.first {
// Prints "10"

See Also

Accessing Elements

var last: Bound?

The last element of the collection.

subscript(Range<Bound>.Index) -> Range<Bound>.Element

Accesses the element at specified position.

subscript(Range<Range<Bound>.Index>) -> Range<Bound>

Accesses the subsequence bounded by the given range.

subscript<R>(R) -> Range<Bound>

Accesses the contiguous subrange of the collection’s elements specified by a range expression.

subscript((UnboundedRange_) -> ()) -> Range<Bound>
func randomElement() -> Bound?

Returns a random element of the collection.

func randomElement<T>(using: inout T) -> Bound?

Returns a random element of the collection, using the given generator as a source for randomness.