Instance Method

max()

Returns the maximum element in the sequence.

Declaration

@warn_unqualified_access func max() -> UInt8?

Return Value

The sequence’s maximum element. If the sequence has no elements, returns nil.

Discussion

This example finds the largest value in an array of height measurements.

let heights = [67.5, 65.7, 64.3, 61.1, 58.5, 60.3, 64.9]
let greatestHeight = heights.max()
print(greatestHeight)
// Prints "Optional(67.5)"

Complexity: O(n), where n is the length of the sequence.

See Also

Finding Bytes

func first(where: (UInt8) -> Bool) -> UInt8?

Returns the first element of the sequence that satisfies the given predicate.

func max(by: (UInt8, UInt8) -> Bool) -> UInt8?

Returns the maximum element in the sequence, using the given predicate as the comparison between elements.

func min() -> UInt8?

Returns the minimum element in the sequence.

func min(by: (UInt8, UInt8) -> Bool) -> UInt8?

Returns the minimum element in the sequence, using the given predicate as the comparison between elements.

func range(of: Data, options: Data.SearchOptions, in: Range<Data.Index>?) -> Range<Data.Index>?

Finds the range of the specified data as a subsequence of this data, if it exists.

typealias Data.SearchOptions

Options that control a data search operation.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software