Reputation: 2259
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
.
Upvotes: 2
Views: 1872
Reputation: 20241
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.
Upvotes: 9