Search code examples
macosfileswift3nsworkspace

Error: Ambiguous reference to member 'open' (Mac OSx) Swift 3


My goal is to open a specified file using the default app associated with its type.

I have the correct path. I do not know how to open a file (e.g. photo.png)

I'm trying to open file by using URL.


Solution

  • The error occurs because you have to use the shared workspace (open is not a class method):

    NSWorkspace.shared().open(...
    

    However if you want to open a specified file using the default app associated with its type you are using the wrong API. You are looking for

    NSWorkspace.shared().openFile(..
    

    This API expects a String rather than an URL.