Using the example from here How to find the max value in a Swift object array?, how do you return the Usr
element rather than the Int age
value?
class Usr {
var age: Int
init(_ age: Int) {
self.age = age
}
}
let users = [Usr(1), Usr(8), Usr(5)]
let maxAge = users.map{$0.age}.max() //this returns 8 instead of the instance