Menu

How to use the current iOS app icon with UIImageView in Swift 3

The following Swift 3 function returns the current icon in your iOS app as a UIImage:

//
// 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!
}
view raw getAppIcon.swift hosted with ❤ by GitHub

 

Example usage:

@IBOutlet weak var myImage: UIImageView!

cell?.myImage.image = getAppIcon()