图表,按字段搜索DB

时间:2018-04-12 08:26:24

标签: cosmicmind

我无法根据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”]对数组进行排序,我该怎么办? 感谢

1 个答案:

答案 0 :(得分:0)

您可以使用sorted功能进行排序,例如:

appoggio.sorted(by: { (a, b) -> Bool in return a["prop"] as! Int < b["prop"] as! Int })

您需要将属性名称和类型更改为相应的名称。