10

He there, I'm trying to open (Launch) a Finder in Mac Catalyst 13.0+. and the 'NSWorkspace' is unavailable in Mac Catalyst

My code:

func openFinder(url: URL?){
    guard let url = url else { return }
    NSWorkspace.shared.activateFileViewerSelecting([url])
}

Error:

'NSWorkspace' is unavailable in Mac Catalyst

Do you have any idea how I can do it in Mac Catalyst?

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Faris
  • 1,206
  • 1
  • 12
  • 18

1 Answers1

7

NSWorkspace is actually available but not visible to the app. You can call the method dynamically using message sending techniques. One way to do that is by using the Dynamic library:

Dynamic.NSWorkspace.sharedWorkspace.activateFileViewerSelectingURLs([url])
Hejazi
  • 16,587
  • 9
  • 52
  • 67