How to get the current application icon in ios

the Reverend picture the Reverend · Feb 23, 2012 · Viewed 17.8k times · Source

Is there a way to get the current application icon in a cocoa-touch app? Thank you.

Answer

samwize picture samwize · Jul 9, 2018

Works for Swift 4.1 and extending it for Bundle.

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

To use in an app, call Bundle.main.icon.