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

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

我的目标是使用与其类型关联的默认应用打开指定文件。

我有正确的路径。我不知道如何打开文件(例如 photo.png)

错误发生是因为您必须使用共享工作区(open不是class方法):

NSWorkspace.shared().open(...

但是,如果您想使用与其类型关联的默认应用程序打开指定文件,那么您使用的是错误的API。您正在寻找

NSWorkspace.shared().openFile(..

此 API 需要 String 而不是 URL