Get iOS application icon

Swift, UIKit

Get the icon for an iOS application

Use this extension to get app's icon:

swift

public extension UIApplication { var appIcon: UIImage? { guard let icons = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any], let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any], let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String], let lastIcon = iconFiles.last else { return nil } return UIImage(named: lastIcon) } }
Usage example:
UIApplication.shared.appIcon