Reputation: 61774
This is what i need to access:
I have a stickers for every language and I need to get an array of urls of these images. How can I do that for ezample for en
directory?
Upvotes: 1
Views: 55
Reputation: 716
You could try to use DirectoryEnumerator
private func getStickersURL(for languageCode: String) -> [URL] {
guard let resourcePath = Bundle.main.resourcePath else {
return []
}
let dirPath = [resourcePath, "Stickers", languageCode].joined(separator: "\\")
return FileManager.default
.enumerator(atPath: dirPath)?
.compactMap { $0 as? String }
.compactMap {
URL(
fileURLWithPath: $0,
relativeTo: URL(fileURLWithPath: dirPath)
).absoluteURL
} ?? []
}
Upvotes: 1
Reputation: 4552
If I remember correctly, asset folder structure isn't preserved during compilation, so it doesn't matter how you organize them, they are stored flat in the app directory.
I suggest building a dictionary for your assets, and then fetching images that way, rather than using file structure.
Upvotes: 1