我正在尝试从项目中的捆绑包加载图像。相反,我得到以下错误:2020-03-20 11:38:53.032321-0400 Journey[4626:1025739] [SwiftUI] No image named 'CountryPicker.bundle/Images/AF.png' found in asset catalog for main bundle (/private/var/containers/Bundle/Application/720B947B-209E-4527-AE1C-B73D905D3D35/Journey.app)
如您在屏幕快照中所见,该图像位于捆绑包中:
这是我的代码:
Picker(selection: $countryOrigin, label: Text("Country of Origin")) {
Section(header: SearchBar(text: $fetcher.searchQuery)) {
List(fetcher.country) { country in
HStack() {
Image("CountryPicker.bundle/Images/\(country.id).png")
Text(country.name)
}
}
}
}
有谁知道如何解决这个问题!
更新
最佳答案
如果将图像移动到xcAssets,它将起作用。您也可以调用Image(uiImage(name:“imageName.png”)!)
关于ios - SwiftUI无法在Bundle中找到图像,但是图像在正确的路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60778215/