Reputation: 33674
How do I figure out what my absolute ${PROJECT_DIR}
path is for my Xcode project? Is there a way to print this in Terminal? How?
Upvotes: 31
Views: 37141
Reputation: 1371
Another interesting method is using a Run Script Phase in Build phases:
Then paste this script that will modify a swift file in your project
fileContent="// DO NOT EDIT,
// THIS IS AUTOMATICALLY GENERATED FILE
// params.swift
//
import Foundation
class Params {
static let srcRoot: String = \"${PROJECT_DIR}\"
}"
echo "${SRCROOT}/YourProjectFolderName/params.swift"
echo "$fileContent" > ${SRCROOT}/YourProjectFolderName/params.swift`
Make sure you added Params.swift in you project.
Upvotes: 0
Reputation: 11568
Run this from Terminal
For a project:
xcodebuild -project yourProject.xcodeproj -target yourTarget -showBuildSettings | grep PROJECT_DIR
For a workspace:
xcodebuild -workspace yourWorkspace.xcworkspace -scheme yourScheme -showBuildSettings | grep PROJECT_DIR
As you can see, you can retrieve any other build settings value
Upvotes: 32
Reputation: 1949
Build Settings -> Preprocess Macros
PROJECT_DIR=@\""$PROJECT_DIR"\"
BUILD_ROOT=@\""$(BUILD_ROOT)"\"
Then you can log it directly
NSLog(@"project dir=%@, BUILD_ROOT_=%@", PROJECT_DIR, BUILD_ROOT);
Upvotes: 38