Contents

init(named:)

Creates an image object from the specified named asset.

Declaration

init?(named name: String)

Parameters

  • name:

    The name of the image asset or file.

Mentioned in

Return Value

An object containing an unconfigured version of the image, or nil if the method could not find the specified image.

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 iOS 13 or later, you may include both types of assets in the same asset catalog. In iOS 12 or earlier, the system automatically chooses the bitmap image.

You can’t use this method to load system symbol images; use the init(systemName:) 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’s best suited for the main screen. 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.

In iOS 9 and later, this method is thread safe.

Special Considerations

If you intend to display an image only once and don’t want it added to the system’s cache, create it using the imageWithContentsOfFile: method instead. Keeping single-use images out of the system image cache can potentially improve the memory use characteristics of your app.

See Also

Loading and caching images