Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Support for descending sort when use grouping #60

Merged

Conversation

bronenos
Copy link
Contributor

@bronenos bronenos commented Jan 8, 2016

Made public just a boolean, whether or not use the grouping.
If true, then use the first sorter as grouping path, automatically.

@isaacroldan
Copy link
Contributor

I understand the issue, but i don't think you need to change all that stuff. The information you need is already passed in the methods, no need to change everything, just the sortSections method:

private func sortSections() {
    guard let sortd =  request.sortDescriptors.first else { return }
    let comparator: NSComparisonResult = sortd.ascending ? .OrderedAscending : .OrderedDescending
    sections.sortInPlace { $0.keyPath.localizedCaseInsensitiveCompare($1.keyPath) == comparator }
}

If you don't want to group, don't pass a sectionKeyPath
This is how NSFetchedResultsController works, and i think is better to try to keep a similar API.

EDIT: If travis fails, review the tests :)

@bronenos
Copy link
Contributor Author

bronenos commented Jan 8, 2016

Well, I see, I lost the local request with all info I need, yes.
And the task could be completed like the way above.

But, by the way, what for do you need to store sectionKeyPath in RRC, if there's no usage of this property inside RRC? And why do programmer have to provide the similar keyPath and first sorter, if it could be simplified? Or the viewpoint is just to be similar with CoreData's API?

@polqf
Copy link
Owner

polqf commented Jan 8, 2016

As it is a NSFetchedResultsController-like Library, we want our API to be as similar as possible to it.
An iOS Developer is used to it, so the goal is to facilitate the migration from CoreData to Realm without having to know a lot about the library itself, while we provide a good implementation.

@bronenos
Copy link
Contributor Author

bronenos commented Jan 8, 2016

Good point. Okay, I got it.
Well, who may apply the changes above? You or me?

@isaacroldan
Copy link
Contributor

Feel free to do it :)

@isaacroldan
Copy link
Contributor

👍

sections.sortInPlace { $0.keyPath.localizedCaseInsensitiveCompare($1.keyPath) == NSComparisonResult.OrderedAscending }
guard let sortd = request.sortDescriptors.first else { return }
let comparator: NSComparisonResult = sortd.ascending ? .OrderedAscending : .OrderedDescending
sections.sortInPlace { $0.keyPath.localizedCaseInsensitiveCompare($1.keyPath) == comparator }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sections.sortInPlace { $0.keyPath.localizedCaseInsensitiveCompare($1.keyPath) == sortd.ascending } ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparator is NSComparisonResult but sortd.ascending is Bool

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault

@polqf
Copy link
Owner

polqf commented Jan 8, 2016

👍

isaacroldan added a commit that referenced this pull request Jan 8, 2016
…ting

Support for descending sort when use grouping
@isaacroldan isaacroldan merged commit 02d57fe into polqf:master Jan 8, 2016
@isaacroldan
Copy link
Contributor

Thanks @bronenos

@polqf
Copy link
Owner

polqf commented Jan 8, 2016

👏

@polqf polqf modified the milestone: 0.4.0 Jan 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants