André Luiz André Luiz - 1 month ago 8
Swift Question

Find the item with the biggest value in a dictionary

I'm implementing some logic to get the closest Beacon and to do that I created a Dictionary where I insert some Measures. My problem is that I don't know how to get the item with the biggest value. Some code below:

struct objBeacon {
var accuracy : Float
var rssi : Float
var positionInList : Float
}

var readBeacons = [String:objBeacon]()


My goal is to get the item (objBeacon) with the biggest
rssi
value, how can I do that without looping through the list?

Answer

The simplest way is this

readBeacons.values.max()

Hope this helps

Comments