使用Realm按多个属性排序 [英] Order by multiple properties using Realm
本文介绍了使用Realm按多个属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用多个属性订购我的Realm结果?
How can I order my Realm results using multiple properties?
我首先使用以下属性对它们进行排序:
I'm sorting them first using one property like this:
allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true)
但现在我还想通过另一个属性timeStart进行二次排序。我试过这样:
But now I also want to do a secondary sort by another property "timeStart". I tried like this:
allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true).sortedResultsUsingProperty("timeStart", ascending: true)
这只会使结果仅由第二个属性排序。请帮助。
This will just make the results sorted only by the second property. Please help.
推荐答案
在RealmSwift中我们可以编写多个这样的属性:
In RealmSwift we can write multiple properties like this:
let sortProperties = [SortDescriptor(property: "dateStart", ascending: true), SortDescriptor(property: "timeStart", ascending: true)]
allShowsByDate = Realm().objects(MyObjectType).sorted(sortProperties)
如果你想使用更多属性,你可以将 SortDescriptor()
的值添加到数组中。
If you want to use more properties,you can add values of SortDescriptor()
to the array.
这篇关于使用Realm按多个属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文