vtourraine / AcknowList

Acknowledgements screen displaying a list of licenses, for example from CocoaPods and Swift Package Manager dependencies.
MIT License
807 stars 60 forks source link

Incorrect sorting when combining plist with custom entries #84

Open grovdata opened 3 years ago

grovdata commented 3 years ago

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 commented 3 years ago

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.