How to get the Xcode project root directory?
Example: /Users/username/MyProjects/Project/
. similar to ${SRCROOT}
I checked through FileManager
urls
and couldn't find the path.
Goal
I am running tests and would like to create a log.txt
file in the project root directory.
AFAIK there is no direct way to access this, but what you can do is this for simulator builds:
Modify your xcode scheme to add an environment var SRCROOT
with the value ${SRCROOT}
In your code, get the system environment using ProcessInfo
:
let srcroot = ProcessInfo.processInfo.environment["SRCROOT"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With