views:

48

answers:

2

I define a path variable in Xcode source tree called "MY_SRC_DIR". I would like to get the value of this environment variable and put it in a NSString in the obj-c code. For example,

-(NSString*) getSourceDir

{

    return @"${MY_SRC_DIR}"; // not the right solution and this is the question

}
+1  A: 

From http://rosettacode.org/wiki/Environment_variables#Objective-C:

[[NSProcessInfo processInfo] environment] returns an NSDictionary of the current environment.

For example:

[[[NSProcessInfo processInfo] environment] objectForKey:@"MY_SRC_DIR"]
highlycaffeinated
A: 

The best answer to this question is the accepted answer on this question.

http://stackoverflow.com/questions/538996/constants-in-objective-c

You'll get the most mileage, and won't need any special methods to get the value you're searching for as long as you import the file into whatever .h/.m file is going to consume said value.

bobwaycott