Add SystemImage protocol
mpospese opened this issue · comments
We have ImageAsset
protocol to allow users to load images from asset catalogs, unit test them, and have a fallback image (so that we can return a non-optional UIImage
. We should do the same thing for system images, e.g. for UIImage(systemName:)
optional initializer.
We could declare a new protocol SystemImage
and either derive it from ImageAsset
or just copy the needed functionality. While we would need:
static var fallbackImage: UIImage { get }
var image: UIImage { get }
func loadImage() -> UIImage?
we do not need (not applicable):
static var bundle: Bundle { get }
static var namespace: String? { get }
loadImage would have default implementation:
func loadImage() -> UIImage? { UIImage(systemName: rawValue) }
Do you have a way to check if the image loaded is the fallback image?
I remember an issue with SpriteKit back in the day where if you loaded a sprite and the sprite didn't exist, it loaded a fallback image, but there was no way to tell that the image load actually failed.