Let say I got an array with Usr
objects. And the Usr
object have the attribute age
. Except from reading the Usr
object one by one, and compare the age
value one by one, is there any shortcuts to do so? Thx.
Finding largest number using max() function Swift provides an in-built method named as max() function. This function returns the maximum number among the given numbers.
M = max( A ) returns the maximum elements of an array. If A is a vector, then max(A) returns the maximum of A . If A is a matrix, then max(A) is a row vector containing the maximum value of each column of A .
Swift 3:
let users = [Usr(15), Usr(25), Usr(20)]
let max = users.map { $0.age }.max()
// max = 25
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With