4

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.

Tal Zion
  • 6,308
  • 3
  • 50
  • 73

1 Answers1

4

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"]
Gereon
  • 17,258
  • 4
  • 42
  • 73