我无法根据BD的值对实体数组进行排序,这是一个例子:
var storage : [Entity] = []
var date1 = Date.customDate(year: 1950, month: 7, day: 8, hour: 0, minute: 0, second: 0)
let codice : UUID = UUID()
let user = Entity(type:"pazienti")
user["codice"] = codice.uuidString
user[“name”] = "Mario"
user[“surname”] = "Rossi"
user["date”] = date1
user["note"] = "xxxxxxxxxxxxxxx xxxxxxx"
storage.append(user)
db.sync()
var appoggio : [Entity] = []
var search = Search<Entity>(graph: db).for(types: "pazienti")
appoggio = search.sync()
storage = appoggio.sorted(by: >)
我需要根据字段[“surname”]对数组进行排序,我该怎么办? 感谢
答案 0 :(得分:0)
您可以使用sorted
功能进行排序,例如:
appoggio.sorted(by: { (a, b) -> Bool in
return a["prop"] as! Int < b["prop"] as! Int
})
您需要将属性名称和类型更改为相应的名称。