Skip to content

Incorrect sorting when combining plist with custom entries #84

@grovdata

Description

@grovdata

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions