Gaurav Vyas Gaurav Vyas - 5 months ago 17
Swift Question

RealmSwift: How can i write Android Realm queries in Swift?

Android :

Here is android realm queries

RealmQuery<class> query = realm.where(class);
query.contains("display_name", "filterQuery");
query.findAllSortedAsync("last_event", Sort.DESCENDING);


Swift:

I want write above android queries in swift 2.0. I am not able to find these queries methods in RealmSwift. Can anyone help me for it ?

Answer
let results = realm.objects(class.self)
    .filter("display_name CONTAINS 'filterQuery'")
    .sorted("last_event", ascending: false)

See also Queries Swift Documentation.