Swift:max方法

一、func max(_: T, _: T)

Returns the greater of two comparable values.
返回比较的两个值中最大的一个

Parameters: 参数
x: A value to compare.
y: Another value to compare.
Returns: The greater of x and y.
If x is equal to y, returns y.

返回:x 和 y 比较最大值。如果x 等于 y , 返回 y.

Declaration:声明
func max(_ x: T, _ y: T) -> T where T : Comparable


二、func max(_: T, _: T, _: T, _: T…)

Returns the greatest argument passed.
返回最大的参数

Parameters:
x: A value to compare.
y: Another value to compare.
z: A third value to compare.
rest: Zero or more additional values.

Returns:
The greatest of all the arguments. If there are multiple equal greatest arguments, the result is the last one.
所有参数的最大。 如果多个数等于最大的参数,返回最后一个。

Declaration
func max(_ x: T, _ y: T, _ z: T, _ rest: T…) -> T where T : Comparable


三、func max()
Returns the maximum element in the sequence.

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)"

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

Declaration
@warn_unqualified_access
func max() -> Self.Element?
Declared In
Sequence