Correct way to find max in an Array in Swift

前端 未结 12 1856
一整个雨季
一整个雨季 2020-11-29 18:05

I\'ve so far got a simple (but potentially expensive) way:

var myMax = sort(myArray,>)[0]

And how I was taught to do it at school:

12条回答
  •  甜味超标
    2020-11-29 18:59

    Here's a performance test for the solutions posted here. https://github.com/tedgonzalez/MaxElementInCollectionPerformance

    This is the fastest for Swift 5

    array.max()

提交回复
热议问题