I used to be able to show my app's icon in the UI using this code:
if let icon = UIImage(named: "AppIcon") {
Image(uiImage: icon)
.resizable()
.frame(width: 64, height: 64)
.cornerRadius(10)
}
But this doesn't work when building with Xcode 16 and iOS 18 SDK.
How can I show my app's icon in the UI without resorting to duplicating the asset?
@rmahmud28 Could you verify the icon file name in the CFBundleIcons dictionary?
For example:
struct ContentView: View {
@State private var iconFileName: String?
var body: some View {
VStack {
if let iconFileName = iconFileName, let icon = UIImage(named: iconFileName) {
Image(uiImage: icon)
.resizable()
.frame(width: 64, height: 64)
.cornerRadius(10)
}
}
.task {
guard
let icons = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as? [String: Any],
let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any],
let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String],
let iconFileName = iconFiles.last
else {
print("Could not find icons in bundle")
return
}
self.iconFileName = iconFileName
}
}
}