简体   繁体   English

获取Xcode扩展的项目位置

[英]Get project location for Xcode extension

I'm working on an Xcode extension, which needs to get the project path, ie the path of the project/workspace from which you run the extension command which I'm making. 我正在开发一个Xcode扩展,它需要获取项目路径,即从中运行我正在执行的扩展命令的项目/工作区的路径。 I've tried something like this: 我已经尝试过这样的事情:

let workspace = NSWorkspace.shared()
let path = workspace.absolutePathForApplication(withBundleIdentifier: Bundle.main.infoDictionary!["CFBundleIdentifier"] as! String)

but it just returns nil. 但它只返回nil。 I have also tried getting it via the FileManager, but it just returns a path of the extension. 我也尝试过通过FileManager来获取它,但是它只是返回扩展名的路径。

App Extensions are always sandboxed, so they don't have arbitrary filesystem access. App Extensions总是沙盒化,因此它们没有任意文件系统访问权限。

For security, Xcode Source Editor Extensions are also only passed the text of the file for which a user has invoked an action, not the path to the file itself or a sandbox extension allowing access to it or its containing project. 为了安全起见,Xcode Source Editor Extensions也仅传递用户为其调用了动作的文件的文本,而不传递文件本身的路径或允许访问该文件或其包含项目的沙箱扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM