【问题标题】:Graph, search sort by field of DB图表,按DB的字段搜索排序
【发布时间】:2018-04-12 08:26:24
【问题描述】:

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

【问题讨论】:

    标签: cosmicmind


    【解决方案1】:

    您可以使用sorted 函数进行排序,例如:

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

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

    【讨论】:

    • 您应该将答案标记为正确,以便其他人知道 :) 谢谢!
    猜你喜欢
    • 2018-10-14
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-18
    • 2022-01-27
    相关资源
    最近更新 更多