phpete
phpete

Reputation: 316

using SRCROOT in Xcode

I am trying to use SRCROOT path in my project like so:

// Create NSTask to interact with console
NSTask *task;
task = [[NSTask alloc] init];

// Set path to script
NSString *launch_path = @"$SRCROOT/Scripts/my_script.rb";
NSLog(launch_path);
[task setLaunchPath:launch_path];

I end up with (in log):

$SRCROOT/Scripts/my_script.rb

I want to end up to a path inside my project's directory like this:

/Application/Scripts/my_script.rb

Can anyone help me understand what I'm doing wrong? Thanks in advance.

Additionally, I've tried the following without success:

..
// Set path to script
NSString *launch_path = [NSString stringWithFormat:@"%@/Scripts/auto_checkin.rb", "$SRCROOT"];
NSLog(launch_path);
..

Upvotes: 0

Views: 2387

Answers (1)

KudoCC
KudoCC

Reputation: 6952

$SRCROOT is meaningless for runtime environment.

If you want to access the document in bundle, make sure the my_script.rb is added in the "Copy Bundle Resources", then try this:

NSString * path = [[NSBundle mainBundle] bundlePath] ;
path = [path stringByAppendingPathComponent:@"my_script.rb"] ;

enter image description here

$SRCROOT is path to the project file(*.xcodeproj) that defines the target. link here enter image description here

The bundle term here represent Application bundle, the application bundle stores everything that the application requires for successful operation. link here

Upvotes: 3

Related Questions