ImageAsset
public protocol ImageAsset : RawRepresentable where Self.RawValue == String
Any named image asset can be loaded from an asset catalog.
All properties and functions have default implementations. At a minimum just have your string-based enum conform
to ImageAsset
(and have an asset catalog with matching assets). If your enum and assets live inside a Swift
package, override bundle
to return .module
. If your assets are categorized within their asset catalog by
a namespace, then override namespace
to return the proper string prefix.
-
bundle
Default implementationThe bundle containing the image assets for this enum (default is
.main
)Default Implementation
The bundle containing the image assets for this enum (default is
.main
)Declaration
Swift
static var bundle: Bundle { get }
-
namespace
Default implementationOptional namespace for the image assets (default is
nil
).Default Implementation
Optional namespace for the image assets (default is
nil
)Declaration
Swift
static var namespace: String? { get }
-
fallbackImage
Default implementationFallback image to use in case an image asset cannot be loaded. (default is a 16 x 16 square filled with
.systemPink
)Default Implementation
Fallback image to use in case an image asset cannot be loaded. (default is a 16 x 16 square filled with
.systemPink
)Declaration
Swift
static var fallbackImage: UIImage { get }
-
image
Default implementationAn image asset for this name value.
Default implementation calls
loadImage
and nil-coalesces tofallbackImage
.Default Implementation
An image asset for this name value.
Default implementation calls
loadImage
and nil-coalesces tofallbackImage
.Declaration
Swift
var image: UIImage { get }
-
loadImage()
Default implementationLoads the image.
Default Implementation
Loads the named image.
Default implementation uses
UIImage(named:in:compatibleWith:)
passing in the associatednamespace
(prepended torawValue
) andbundle
.Declaration
Swift
func loadImage() -> UIImage?
Return Value
The named image or else
nil
if the named asset cannot be loaded.