How can I get all image names in asset catalog group?

前端 未结 2 1526
无人及你
无人及你 2020-12-16 04:03

In my app I had a folder of images from which I was getting the names to use as keys to a Dictionary. I have now moved all images to an asset catalog and created groups for

相关标签:
2条回答
  • 2020-12-16 04:05

    You have two choices:

    • Don't Do That. Go right on using a folder of images.

    • Supply the keys in some other way. If you don't want to hard-code them into the code itself, you could make a text file. But of course you will have to keep that text file updated as you add / remove images.

    You'll notice that I didn't say you could magically introspect the asset catalog. That's because you can't.

    0 讨论(0)
  • 2020-12-16 04:22

    So (following matt's suggestion) here is what I did:

    I created a RunScript build phase to run before compiling

    enter image description here

    and used a script to create a txt file with the names of the files that I can then use during runtime

    #!/bin/sh
    >./your_app_folder/fileNames.txt
    for FILE in ./your_app_folder/Images.xcassets/actions/*; do
    echo $FILE >> ./your_app_folder/fileNames.txt
    done
    
    0 讨论(0)
提交回复
热议问题