Contents

init(named:in:with:)

Creates an image by using the named image asset that’s compatible with the configuration you specify.

Declaration

init?(named name: String, in bundle: Bundle?, with configuration: UIImage.Configuration?)

Parameters

  • name:

    The name of the image asset or file.

  • bundle:

    The bundle containing the image file or asset catalog. Specify nil to search the app’s main bundle.

  • configuration:

    The image configuration that you want. Use this parameter to specify traits and other details that define which variant of the image you want. For example, when requesting a custom symbol image, you can specify whether you want the thin, regular, or bold image variant.

Mentioned in

Return Value

An object containing the image variant that matches the specified configuration data, or nil if no suitable image was found.

Discussion

When searching the asset catalog, this method prefers an asset containing a symbol image over an asset with the same name containing a bitmap image. Because the system supports symbol images in iOS 13 or later, you may include both types of assets in the same asset catalog. The system automatically falls back to the bitmap image on earlier versions of iOS.

You can’t use this method to load system symbol images; use the init(systemName:withConfiguration:) method instead.

This method checks the system caches for an image object with the name you specify, and returns the variant of that image that best matches the trait collection you specify. If a matching image object isn’t in the cache, this method creates the image from an available asset catalog or loads the image from disk.

The system may purge cached image data at any time to free up memory. Purging occurs only for unused images that are in the cache.

See Also

Loading and caching images