Skip to content
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

Incorrect sorting when combining plist with custom entries #84

Open
grovdata opened this issue Jun 22, 2021 · 1 comment
Open

Incorrect sorting when combining plist with custom entries #84

grovdata opened this issue Jun 22, 2021 · 1 comment

Comments

@grovdata
Copy link

I discovered a problem when you combine Cocoapods plist with additional entries.

let viewController = AcknowListViewController(fileNamed: "file")

// Add a special entry
let someLicenseThatsNotInCocoapods = Acknow(title: "Foo", text: "baz")
vc.acknowledgements.append(someLicenseThatsNotInCocoapods)

navigationController.pushViewController(viewController, animated: true)

This does not work out so great, as Foo will always be appended to the end of the list, and you expect them to be sorted. I use this as workaround:

let viewController = AcknowListViewController(fileNamed: "file")

// Add a special entry
let someLicenseThatsNotInCocoapods = Acknow(title: "Foo", text: "baz")
vc.acknowledgements.append(someLicenseThatsNotInCocoapods)

// Sort entries (stolen from load() )
vc.acknowledgements = vc.acknowledgements.sorted(by: {
            (ack1: Acknow, ack2: Acknow) -> Bool in
            let result = ack1.title.compare(ack2.title, options: [], range: nil, locale: Locale.current)
            return (result == ComparisonResult.orderedAscending)
})
navigationController.pushViewController(viewController, animated: true)

It could be solved in a number of ways, perhaps more initialisers with customAcknowledgements: [Acknow] as argument, or just sort the entries in didSet of AcknowListViewController.acknowledgements.

@vtourraine
Copy link
Owner

Thank you for submitting this issue!

I understand your point, but maybe if someone wants to customize the array of acknowledgements, then they should be responsible for sorting them too? To put it differently: what if someone wants a different order?

Like you said, it could be solved in a number of ways, but I’m not sure which one would be the most appropriate (not adding complexity, but keeping things easy-to-use). Would love more feedback on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants