3

I am new to xCode. I want to create an array of UIImage from the folder in Assets Catalogue - see screenshot ("Brands" folder).

Assets folder details

To load it in a UITableView like this:

private func loadLocalBrands() {

    // Load images names from assets and add them to array
    let names : [String] = ["Avon","Dove","Faberlic","Grand","GreenLight","Loreal",
                            "Loreal", "MaxFactor", "Nivea", "Olay", "Oriflame",
                            "Rexona","Schwarzkopf","Spaquatoria","Wella"]

        for name in names{
            brands.append(Brand.init(name: name, photo: 
            UIImage(named: name), rating: Int(arc4random_uniform(5) + 1))!)
        }
    }

and it works properly - see screenshot

simulator screenshot

But if I will add sooner more images, I will need to expand "names" array too.

So I want to get list of files that located in "Brands" folder within the Assets catalogue.

carbonr
  • 6,049
  • 5
  • 46
  • 73
  • The question that is indicated as being the same as this and already having answer is in no way the same as this and the answer there isn't even marked as accepted. This should never have been closed or marked as a duplicate. – Christopher King May 02 '18 at 00:11

1 Answers1

0

You are over-engineering this, its best to maintain a list of your assets that you want to display to the user. You will have to add assets to the project and repackage which is a good time to add new items to the list.

Also this is why things like this are manged from server in case you didn't think of it.

Another issue is that the asset catalogue is a product of Xcode whereas its not available when the IPA file of the app is created in the same format (in my understanding). So this approach will fail even if you were to work around and read the file list somehow.

carbonr
  • 6,049
  • 5
  • 46
  • 73