1

I am trying to use the new -[NSOpenPanel setAllowedContentTypes:] and looking for equivalent of -[NSOpenPanel setAllowedFileTypes:[NSImage imageTypes]].

Is this equivalent:

openPanel.allowedContentTypes = [UTType.image] [openPanel setAllowedFileTypes:@[kUTTypeImage]]; //[openPanel setAllowedFileTypes:[NSImage imageTypes]]; 

NOTE: Converting NSImage.imageTypes to UTType arrays are different. 4 identifiers fail conversion ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur")

let types = NSImage.imageTypes.count //61 let utTypes = NSImage.imageTypes.compactMap { UTType($0) } //57 let coreTypes = CGImageSourceCopyTypeIdentifiers() //59; doesn't have SVG 

NOTE2: PDF doesn't conform to UTType.image

print(UTType.pdf.conforms(to: UTType.image)) //false 
2
  • 2
    seems like you found out everything there’s to know. i can’t quite read the exact question. Commented Jul 23, 2024 at 9:06
  • WARNING: "openPanel.allowedContentTypes = [UTType.image]" will accept sketch files Commented Oct 15 at 18:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.