gpt4 book ai didi

ios - 使用 Realm 按多个属性排序

转载 作者:IT王子 更新时间:2023-10-29 05:06:31 25 4
gpt4 key购买 nike

如何使用多个属性来排序我的 Realm 结果?

我首先使用这样的一个属性对它们进行排序:

allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true)

但现在我还想通过另一个属性“timeStart”进行二次排序。我试过这样:

allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true).sortedResultsUsingProperty("timeStart", ascending: true)

这只会使结果仅按第二个属性排序。请帮忙。

最佳答案

在 RealmSwift 中,我们可以像这样编写多个属性:

let sortProperties = [SortDescriptor(property: "dateStart", ascending: true), SortDescriptor(property: "timeStart", ascending: true)]
allShowsByDate = Realm().objects(MyObjectType).sorted(sortProperties)

如果你想使用更多的属性,你可以将SortDescriptor()的值添加到数组中。

关于ios - 使用 Realm 按多个属性排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27365809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com