-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to sort RLMResults using a comparison block #1265
Comments
I don't think this is something we will want to do. First it requires creating accessors for every element which can get kind of slow. Second, we will have to hold onto the sort block as long as the RLMResults exists and to reapply that block for live queries. This obviously has potential problems. I think what we should do instead is to bring back the |
I agree there are disadvantages to this approach, but it's still better than the alternatives. Unless there's another solution that we have yet to consider. I can think of a few downsides to encouraging users to use an
This being said, there might be another approach we have yet to consider, but until then, I think an |
Just +1ing this. I'm currently trying to sort an array of locations by a computed 'distance' property. This 'distance' property represents the distance between the location and a user selected point. I've been using RLMResults as my data model for my tableview, as it has sorting built in. Unfortunately, was a bit stumped and now will have to use standard arrays. |
I guess we should add this and make clear in the docs that performance will be much worse than using sortDescriptors. This is still blocked on core support support for manual construction and freezing of TableViews |
+1 I'm dealing with the same use case that @ceeK highlighted, sorting on a computed distance property. |
+1, i also need this feature. |
+1 for needing it in particular with distance |
Adding my +1 to this. Even if using this came with a significant performance tradeoff versus sort descriptors (when using the feature, obviously), it has to be better than my "map to an array, run a custom sort, and regenerate on every write notification" solution I'm currently stuck with. This would also give relief to the "sort on relationship properties" crowd (#1277) while they wait for support within sort descriptors (myself included!). |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
More specifically if we could have the |
+1 |
+1 |
+1 here as well. Trying to sort based on one optional NSDate and another non-optional NSDate. Trying to look at whether the optional date exists and if so us it for sorting, if not fall back to the non-optional date. |
+1 |
1 similar comment
+1 |
you should also annotate that sortedResultsUsingDescriptors expects an array of RLMSortDescriptor not a NSSortDescriptor... |
@peterpaulis nice catch! See #4318. |
+1 |
1 similar comment
+1 |
+1 for needing it with distance. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Was this implemented already or no? |
+1 |
+1 Stumped by the same need as mentioned above about sorting based on computed distance. |
Still no support? This is a major usecase |
I am also finding a need for this. +1 |
+1 for |
It's been 5 years now.
As I understand, this feature has been implemented quite recently: So the question is, can this feature be implemented now? |
This year it will be 10 years anniversary since the ticket was created :) Any updates/plans for this? |
This has been open a long time. Perhaps there is a current solution if you need to sort Realm results via a block (closure in Swift). Would this suffice? Assume a Person object
and then to query for person objects sorted by name - note the
and the output would be Person objects sorted by name (or whatever property or comparison you choose) I think that meets the requirements of the git title "Add ability to sort RLMResults using a comparison block" |
We should discuss the feasibility of this, especially around auto-updating. It may not be fully possible to do this without the ability to freeze
RLMResults
. If that's the case, we should add theblocked
tag to this issue.The API could look something like
-[RLMResults sortedResultsUsingBlock:]
, which would require constructing the accessors for each item in theRLMResults
and then accessing the properties accessed in the block, but it would allow people to sort in any way they like.Thoughts @alazier @tgoyne?
The text was updated successfully, but these errors were encountered: