Realm-cocoa: How can I do multiple sorting?

Created on 8 Jun 2016  路  2Comments  路  Source: realm/realm-cocoa

Hi guys,

Can someone help?

I want to get all the isTopConversation ( actually has 0 and 1) equals 1 at the top a few then the rest for the conversation I want sorted by updatedUnixTime. Like:

content, isTopConversation, updatedUnixTime

  1. aaaa, 1, 123
  2. bbbb, 1, 234
  3. cccc, 0, 34343
  4. dddd, 0, 34340

my current query is like this, but it seems to be that the first isTopConversation is not working.
realm.objects(Conversation).filter(predicate).sorted("isTopConversation", ascending: false).sorted("updatedUnixTime", ascending: false)

T-Help

Most helpful comment

Results.sorted has a second overload that takes a sequence of SortDescriptors to sort by:

realm.objects(Conversation).filter(predicate).sorted([SortDescriptor(property: "isTopConversation", ascending: false),
                                                      SortDescriptor(property: "updatedUnixTime", ascending: false)])

All 2 comments

Results.sorted has a second overload that takes a sequence of SortDescriptors to sort by:

realm.objects(Conversation).filter(predicate).sorted([SortDescriptor(property: "isTopConversation", ascending: false),
                                                      SortDescriptor(property: "updatedUnixTime", ascending: false)])

Nice, thanks Mark! It works, closing issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javierjulio picture javierjulio  路  3Comments

jpsim picture jpsim  路  3Comments

carvalho-oak picture carvalho-oak  路  3Comments

i-schuetz picture i-schuetz  路  3Comments

dmorrow picture dmorrow  路  3Comments