简体   繁体   中英

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. 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. I have also tried getting it via the FileManager, but it just returns a path of the extension.

App Extensions are always sandboxed, so they don't have arbitrary filesystem access.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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