This question covers UIImage as well as NSImage. Both types have some failable initializer, like this one:
init?(named name: String)
And this makes perfectly sense, since the resource could not be found in the bundle for some reasons. And in that case returning “nil” is a perfect solution.
But if I use the convenience initializer with type ‘ImageResource’, the initializer seems not to be failable:
UIImage(resource: ImageResource(name: "SomeName", bundle: .main))
So I have two questions:
- Why is this initializer not failable ? (it would also be possible,
that the resource could not be found in the bundle) - What is returned by this initializer, technically it must be an UIImage (but with what kind of content)?