I'd like to find the highest value in my array. I found the method .max() in Apples documentation.
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)"
My array has custom datatype. The datatype contains two variables from type integer. How can I find the highest value from one of the variables?
This is my class.
class Example: Codable {
// Variables
var value1: Int
var value2: Int
// Init
init(_value1: Int, _value2: Int) {
value1 = _value1
value2 = _value2
}
}
Comparable