How to get UIImage of AppIcon?

The problem is that the AppIcon from the asset catalog is not placed in the the catalog after compiling. Instated it it copied into your apps bundle, just like before.

The name conversion used when copying the icon to the app bundle is AppIcon<size>.png, where the size is for example 40x40 or 72x72

You can get your apps icons by specifying the size of the app icon you want:

UIImage *appIcon = [UIImage imageNamed:@"AppIcon40x40"];

The >iOS10 answer is:

Copy & paste this extension.

extension Bundle {
  
  var icon: UIImage? {
    
    if let icons = infoDictionary?["CFBundleIcons"] as? [String: Any],
       let primary = icons["CFBundlePrimaryIcon"] as? [String: Any],
       let files = primary["CFBundleIconFiles"] as? [String],
       let icon = files.last
    {
      return UIImage(named: icon)
    }
    
    return nil
  }
}

Then just call this:

Bundle.main.icon

SwiftUI:

Image(uiImage: Bundle.main.icon ?? UIImage())

Update Sep 12 2022: This doesn't work anymore, as of iOS 16.0.0 at least.

The methods of loading the main app icon highlighted in other answers like from Rufat Mirza used to work, and still does for debug builds, but I got an app rejection from Apple saying the app was crashing on launch. Turns out that the builds that contained this code started crashing on iOS 16, but only when installed via App Store/TestFlight (builds using the "Release" Configuration). What's more weird is that builds using the "Release" Configuration compiled via Xcode also wouldn't crash, only when uploaded to App Store and downloaded from TestFlight, so keep this in mind.

The fix was, unfortunately, to create a new Image asset with the same content as the AppIcon asset.

Note that this workaround still works for macOS as of the 12.5.1 and whatever macOS version Apple is using when reviewing their apps as of today, but since I already had to duplicate the asset for iOS, I also used the same asset for macOS to avoid this little hack :)