The actual interface of that function is:
func max(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> Element?
The predicate argument defines what "increasing order" is for the purposes of the function. When you use >
as the predicate, you're saying that a > b
implies that a
is before b
in the order you want to use. Since 3 > 2
and 2 > 1
, 1
is the "maximum" according to the predicate that you provided.
As @suyashsrijan notes, you can use .max()
if you want the "natural" ordering.