Menu

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


Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 12 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 14 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 15 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466

Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 29 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 31 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 32 in /home/customer/www/thewirelessguy.co.uk/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
let primaryIconsDictionary = NSBundle.mainBundle().infoDictionary?["CFBundleIcons"]?["CFBundlePrimaryIcon"] as? NSDictionary
let iconFiles = primaryIconsDictionary!["CFBundleIconFiles"] as! NSArray
let lastIcon = iconFiles.lastObject as! NSString //last seems to be largest, use first for smallest
let theIcon = UIImage(named: lastIcon as String)
let iconImageView = UIImageView(image: theIcon)

An updated Swift 3 example is now available:

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