App icon doesn't show in UI when building with Xcode 16

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?

Answered by DTS Engineer in 791165022

@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
        }
    }
}
Accepted Answer

@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
        }
    }
}
App icon doesn't show in UI when building with Xcode 16
 
 
Q