2

Does anyone know how to get a related Xcode project directory right from the code? I've tried to accomplish it with the pwd environment, but it only works in Build Phases > Run Script.

2
  • Do you mean from the app code that you are debugging in Xcode? Commented Oct 18, 2017 at 13:57
  • @LouFranco yes, something like that: print($SRCROOT) :( Commented Oct 18, 2017 at 15:09

1 Answer 1

9

for individual files you can either use the C-macro __FILE__, or the swift-literal #file.

From the Swift Docs (search for Literal Expressions on the page)

  • #file (String) The name of the file in which it appears.
  • #line (Int) The line number on which it appears.
  • #column (Int) The column number in which it begins.
  • #function (String) The name of the declaration in which it appears.

Once you have the path to the file it should be easy to find your way to the project root.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.