Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use current iOS app icon with UIImageView in Swift 3
// GetAppIcon.swift
// Get the AppIcon from Assets and return it as a UIImage
// Created by Stephen Mullen
import UIKit
func getAppIcon() -> UIImage {
let iconsDictionary = Bundle.main.infoDictionary?["CFBundleIcons"] as? NSDictionary
let primaryIconsDictionary = iconsDictionary?["CFBundlePrimaryIcon"] as? NSDictionary
let iconFiles = primaryIconsDictionary!["CFBundleIconFiles"] as! NSArray
// First will be smallest for the device class, last will be the largest for device class
let lastIcon = iconFiles.lastObject as! NSString
let icon = UIImage(named: lastIcon as String)
return icon!
Copy link

ftp27 commented Sep 5, 2017

extension UIImage {
    static var appIcon: UIImage? {
        guard let iconsDictionary = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String:Any],
              let primaryIconsDictionary = iconsDictionary["CFBundlePrimaryIcon"] as? [String:Any],
              let iconFiles = primaryIconsDictionary["CFBundleIconFiles"] as? [String],
              let lastIcon = iconFiles.last else { return nil }
        return UIImage(named: lastIcon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment