Order by multiple properties using Realm Order by multiple properties using Realm swift swift

Order by multiple properties using Realm


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.


Figured it out like this:

let sortProperties = [RLMSortDescriptor(property: "dateStart", ascending: true), RLMSortDescriptor(property: "timeStart", ascending: true)]allShowsByDate = Show.allObjects().sortedResultsUsingDescriptors(sortProperties)


Updated for Swift 4 syntax

let sortProperties = [SortDescriptor(keyPath: "queue"), SortDescriptor(keyPath: "name")]let dogList = realm.objects(Dog.self).sorted(by: sortProperties)