Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Xcode root folder directory path using Swift

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.

like image 318
Tal Zion Avatar asked Oct 16 '25 07:10

Tal Zion


1 Answers

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"]
like image 55
Gereon Avatar answered Oct 17 '25 21:10

Gereon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!