HEIC images within the assets folder not loaded HEIC images within the assets folder not loaded swift swift

HEIC images within the assets folder not loaded


Apple's asset compiler re-encodes all images that come into it in a variety of internal formats, some standard and some proprietary, depending on a bunch of factors, including the type of image, the target OS version, and possibly other factors. Unfortunately, at the time of this writing, the asset compiler seems to be buggy as far as HEIC files are concerned; if I try to put an HEIC file into an asset catalog, it appears to be left out. The image data is not copied into the Assets.car file, which itself is only 16 KB in size, containing only a few empty B-trees. Therefore, when you try to load the image using UIImage, you get nothing.

Fortunately, since the asset compiler recodes all images fed into it anyway, you can just re-encode your images to another format (I recommend PNG, as it is lossless), and the resulting file that the end-user receives should be identical to what it would have been with the HEIF input file (and ironically, it might end up being coded as HEIF, since the assets format supports it). So that is what I would do until Apple fixes this bug in the asset compiler.


After a big research through Radar and Apple DTS, I received the following answer from an engineer who contacted other engineering teams:

“Hi,

My email started a long email thread involving a number of engineers tracing your question through the system. Eventually, they found that HEIC format is not supported in image assets and in other parts of the system at this time where jpg and png files are presently used. Specifically, I am referring to automatically loaded resources such as those saved in storyboards or other Xcode generated resources and files. There is no workaround available at this time.

This does not mean that you cannot use HEIC images in your app. If you would like use an HEIC image in your code, then you can use Image I/O to load the image.

Please try again in future versions of the operating system.”

TL;DR:

It’s not possible to use HEIF on the assets folder yet. Maybe in the future.

UPDATE:

Tested on Xcode 10 beta 5 and now the Assets.car contains the HEIF images, which indicates it's possible to use HEIF images as part of the assets folder.