adit
adit

Reputation: 33674

Find the ${PROJECT_DIR} for an Xcode project

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

Answers (3)

Kamen Dobrev
Kamen Dobrev

Reputation: 1371

Another interesting method is using a Run Script Phase in Build phases:

enter image description here

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

Xavi Gil
Xavi Gil

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

vk.edward.li
vk.edward.li

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

Related Questions