Contents

setAlternateIconName(_:completionHandler:)

Changes the icon the system displays for the app.

Declaration

func setAlternateIconName(_ alternateIconName: String?, completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
func setAlternateIconName(_ alternateIconName: String?) async throws

Parameters

  • alternateIconName:

    The name of the alternate icon, as declared in the CFBundleAlternateIcons key of your app’s Info.plist file. Specify nil if you want to display the app’s primary icon, which you declare using the CFBundlePrimaryIcon key. Both keys are subentries of the CFBundleIcons key in your app’s Info.plist file.

  • completionHandler:

    The handler to execute with the results. After attempting to change your app’s icon, the system reports the results by calling your handler. The handler executes on a UIKit-provided queue, and not necessarily on your app’s main queue. The handler has no return value and takes the following parameter:

    error

    On success, the value of this parameter is nil. If an error occurred, this parameter contains the error object indicating what happened and the value of the Alternateiconname property remains unchanged.

Discussion

Use this method to change your app’s icon to its primary icon or to one of its alternate icons. You can change the icon only if the value of the supportsAlternateIcons property is true.

You must configure your app’s primary icon asset in the “App Icons and Launch Images” section of the General pane or set it directly using the “Primary App Icon Set Name” build setting. You specify the names of additional icon assets available to your app using the “Alternate App Icon Sets” build setting. Xcode uses these setting to generate the entries for CFBundlePrimaryIcon and CFBundleAlternateIcons under the top-level key CFBundleIcons. For more information, see Build settings reference and Configuring your app icon using an asset catalog.

See Also

Managing the app’s icon