Created
February 16, 2025 17:06
-
-
Save DimitarNestorov/398c635551bbc5a70244e08711d501b3 to your computer and use it in GitHub Desktop.
Generate a markdown table of supported image file formats in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let sourceUTIs = CGImageSourceCopyTypeIdentifiers() as? [String] ?? [] | |
| let destinationUTIs = CGImageDestinationCopyTypeIdentifiers() as? [String] ?? [] | |
| var markdownTable = """ | |
| | UTI | File Extensions | Source | Destination | Notes | | |
| | - | - | - | - | - | | |
| """ | |
| let allUTIs = Set(sourceUTIs).union(Set(destinationUTIs)) | |
| func fileExtension(for uti: String) -> String { | |
| if let type = UTType(uti), let extensions = type.tags[.filenameExtension] { | |
| return extensions.map { "`\($0)`" }.joined(separator: ", ") | |
| } | |
| return "N/A" | |
| } | |
| let sortedUTIs = allUTIs.sorted { uti1, uti2 in | |
| let isPublic1 = uti1.hasPrefix("public.") | |
| let isPublic2 = uti2.hasPrefix("public.") | |
| let inSource1 = sourceUTIs.contains(uti1) | |
| let inDest1 = destinationUTIs.contains(uti1) | |
| let inSource2 = sourceUTIs.contains(uti2) | |
| let inDest2 = destinationUTIs.contains(uti2) | |
| let both1 = inSource1 && inDest1 | |
| let both2 = inSource2 && inDest2 | |
| if both1 != both2 { | |
| return both1 | |
| } | |
| if isPublic1 != isPublic2 { | |
| return isPublic1 | |
| } | |
| return uti1 < uti2 | |
| } | |
| for uti in sortedUTIs { | |
| let ext = fileExtension(for: uti) | |
| let sourceCheck = sourceUTIs.contains(uti) ? "✅" : "❌" | |
| let destinationCheck = destinationUTIs.contains(uti) ? "✅" : "❌" | |
| markdownTable += "\n| `\(uti)` | \(ext) | \(sourceCheck) | \(destinationCheck) | |" | |
| } | |
| print(markdownTable) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public.heicheicpublic.heicsheicspublic.jpegjpeg,jpg,jpepublic.jpeg-2000jp2,jpf,jpx,j2k,j2cpublic.pbmpublic.pngpngpublic.pvrpublic.tifftiff,tifcom.adobe.photoshop-imagepsdcom.apple.atxcom.apple.icnsicnscom.compuserve.gifgifcom.ilm.openexr-imageexrcom.microsoft.bmpbmp,dibcom.microsoft.ddscom.microsoft.icoicocom.truevision.tga-imagetgaorg.khronos.astcorg.khronos.ktxorg.khronos.ktx2public.avciavcipublic.avifavifpublic.avispublic.heifheif,hifpublic.jpeg-xljxlpublic.mpo-imagempopublic.radiancecom.adobe.pdfpdfcom.adobe.raw-imagedngcom.canon.cr2-raw-imagecr2com.canon.cr3-raw-imagecr3com.canon.crw-raw-imagecrwcom.canon.tif-raw-imagetifcom.dxo.raw-imagedxocom.epson.raw-imageerfcom.fuji.raw-imagerafcom.hasselblad.3fr-raw-image3frcom.hasselblad.fff-raw-imagefffcom.kodak.raw-imagedcrcom.konicaminolta.raw-imagemrwcom.leafamerica.raw-imagemoscom.leica.raw-imagerawcom.leica.rwl-raw-imagerwlcom.microsoft.curcom.nikon.nrw-raw-imagenrwcom.nikon.raw-imagenefcom.olympus.or-raw-imageorfcom.olympus.raw-imageorfcom.olympus.sr-raw-imageorfcom.panasonic.raw-imagerawcom.panasonic.rw2-raw-imagerw2com.pentax.raw-imagepefcom.phaseone.raw-imageiiqcom.samsung.raw-imagesrwcom.sony.arw-raw-imagearwcom.sony.axr-raw-imageaxrcom.sony.raw-imagesrfcom.sony.sr2-raw-imagesr2org.webmproject.webpwebpUnless noted otherwise the format is supported since at least iOS 14.3 (18C66)