问题
I have a xcassets hierarchy as follow:
xcasset
| Set1 (folder)
| | Birds (folder)
| | | image1
| | | image2
| | | image3
| | | image4
| | Foo (folder)
| | Bar (folder)
How can I (elegantly?):
- get the list of group in the "Set1" group
- load an [UIImage] from a specific group
So I could do something that looks like ~
- list all folders in "Set1"
- pick one folder randomly
- load all images of that folder in a [UIImage]
The cool thing here would be to be able to update sets without having to change anything in the code (and not having to set a specific name policy)
回答1:
You cannot introspect an asset catalog. So you cannot ask it questions like what "folders" Set1 contains, or what images Birds contains.
If you need that sort of introspection, don't use an asset catalog. Use folder references embedded into the top level of your app bundle. Now you have real folders and files, and you can navigate the folders and ask what image files they contain using ordinary FileManager methods.
来源:https://stackoverflow.com/questions/48720250/load-array-of-images-using-group-in-xcassets