i want to sort some array whit a specific condition, where if after you compare 3 other condition and they are the same it will check wether the boolean is true or false. if it's true i want it to be sorted first but idk how to do it since boolean is not comparable here's my array i want to sort
public struct Beef
{
let country:Country
var grade:Character
let condition:Condition
let marbling:Bool
}
public var beefs:[Beef]
{
[
Beef(country: .id, grade: "C", condition: .fresh, marbling: false),
Beef(country: .us, grade: "B", condition: .frozen, marbling: true),
Beef(country: .au, grade: "A", condition: .fresh, marbling: true),
Beef(country: .id, grade: "A", condition: .frozen, marbling: false),
Beef(country: .us, grade: "A", condition: .fresh, marbling: true),
Beef(country: .au, grade: "A", condition: .fresh,marbling: false),
Beef(country: .au, grade: "A", condition: .fresh,marbling: true)
]
}
and this is my sort code
func sortBythree()
{
let sortedBeef = beef.sorted { left, right in
if left.country == right.country
{
if left.grade == right.grade
{
if left.condition == right.condition
{
//what to write? for bool comparison
}
return left.condition > right.condition
}
return left.grade < right.grade
}
return left.country < right.country
}
for beef in sortedBeef
{
print(beef.country,beef.grade,beef.condition,beef.marbling)
}
}
and this is the result
'''
id A frozen false
id C fresh false
us A fresh true
us B frozen true
au A fresh true
au A fresh false
au A fresh true
'''
i want true to be sorted before false but idon't know how