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)
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.
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)
If you want to use more properties,you can add values of SortDescriptor()
to the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With