Question: Arrange Int order displayed from .plists in Swift?


Arrange Int order displayed from .plists in Swift?

Answers 0
Added at 2016-12-28 08:12

I have a list of plist files that reads an Int and displays it in my collectionView. The issue I'm having is that the collectionview doesn't display the Int in order from 1st to last. It displays them in the order of the plist files themselves. in example

let resourceNames = [
        "extra-old", "extra-3", "extra-5", "extra-6", "extra-7", "extra-8", "extra-9", "extra-11", "extra-14", "extra-15", "extra-16", "extra-1"

    _ = resourceNames.flatMap { resourceName -> [Animal] in
        guard let plistPath = Bundle.main.path(forResource: resourceName, ofType: "plist") else {
            fatalError("Nil path") //TODO: add error handling!
        guard let array = NSArray(contentsOfFile: plistPath) else { fatalError("File read error") }

        let arrayOfDicts ={ element -> [String: Any] in
            guard let dict = element as? [String: Any] else { fatalError("Element is not a dictionary!") }
            return dict

        let newAnims =
        anims.append(contentsOf: newAnims)
        return newAnims


lets say "extra-1.plist" has Int 1-50 and "extra-2.plist" has Int 51-100. If I were to list "extra-2" on the resourceNames first, than the collectionView would display "51-100 & 1-50" instead of "1-50 & 51-100". I'm stumped as to the code I would need so that it displays the Ints it reads in order, regardless of the order of the plist files.

Answers to

Arrange Int order displayed from .plists in Swift?

Source Show
◀ Wstecz