Skip to main content
added 69 characters in body
Source Link
Marek H
  • 5.6k
  • 3
  • 32
  • 46

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

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

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
added 69 characters in body
Source Link
Marek H
  • 5.6k
  • 3
  • 32
  • 46

I am trying the most simplest way to convertuse 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 array. However the resulting arrays are different as. 4 identifiers fail conversion ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur") are returning nil. Alternatively is there any new convenient method for [NSOpenPanel setAllowedContentTypes:@[UTTypes]] to allow images only?

How to get equivalent array?

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

I am trying the most simplest way to convert NSImage.imageTypes to UTType array. However the resulting arrays are different as 4 identifiers ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur") are returning nil. Alternatively is there any new convenient method for [NSOpenPanel setAllowedContentTypes:@[UTTypes]] to allow images only?

How to get equivalent array?

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

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
added 61 characters in body
Source Link
Marek H
  • 5.6k
  • 3
  • 32
  • 46

I am trying the most simplest way to convert NSImage.imageTypes to UTType array. However the resulting arrays are different as 4 identifiers ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur") are returning nil. Alternatively is there any new convenient method for [NSOpenPanel setAllowedContentTypes:@[UTTypes]] to allow images only?

How to get equivalent array?

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

I am trying the most simplest way to convert NSImage.imageTypes to UTType array. However the resulting arrays are different as 4 identifiers ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur") are returning nil. Alternatively is there any new convenient method for [NSOpenPanel setAllowedContentTypes:@[UTTypes]] to allow images only?

How to get equivalent array?

let types = NSImage.imageTypes.count //61
let utTypes = NSImage.imageTypes.compactMap { UTType($0) } //57
let coreTypes = CGImageSourceCopyTypeIdentifiers() //59

I am trying the most simplest way to convert NSImage.imageTypes to UTType array. However the resulting arrays are different as 4 identifiers ("com.apple.atx", "org.khronos.ktx2", "public.avis", "com.microsoft.cur") are returning nil. Alternatively is there any new convenient method for [NSOpenPanel setAllowedContentTypes:@[UTTypes]] to allow images only?

How to get equivalent array?

let types = NSImage.imageTypes.count //61
let utTypes = NSImage.imageTypes.compactMap { UTType($0) } //57
let coreTypes = CGImageSourceCopyTypeIdentifiers() //59; doesn't have SVG
added 61 characters in body
Source Link
Marek H
  • 5.6k
  • 3
  • 32
  • 46
Loading
Source Link
Marek H
  • 5.6k
  • 3
  • 32
  • 46
Loading