Reputation: 323
I have a class:
class Rates{
var price:Double?
}
Multidimensional Array:
var rates:[[Rates]] = [[],[],[],[],[]]
I am trying to sort every array in rates from smallest Double to Largest. Here is what I tried
for x in 0 ..< 4 {
self.shippingRates[x].sort({ (Rates, Rates2) -> Bool in
return Rates.price < Rates2.price
})
}
But for some reason the sort isn't working, when i display the data it doesn't show up sorted. What am I doing wrong?
Upvotes: 0
Views: 72
Reputation: 93191
Because sort
returns a new array, which you didn't retain. Use sortInPlace
instead:
for x in 0 ..< 4 {
self.shippingRates[x].sortInPlace { $0.price < $1.price }
}
Upvotes: 1