tags:

views:

233

answers:

2

I want to do a conditional statement in my prototype such as:

if (${EXECUTABLE_NAME} == "MyAppName")

as I am using multiple targets for the custom skins of the app.

Thanks

+1  A: 

You can set a preprocessor-macro for your target name. To do so, all you do is open your targets info panel, find the section for "pre-processor macro" and enter "MY_APP_NAME".

alt text

Then at compile time, all you have to do is check if this exists.

-(BOOL) isMyAppName {
    #ifdef MY_APP_NAME
        return YES;
    #else
        return NO;
    #endif
}

And later in your code, you can call this function to determine if the target is the one you want.

coneybeare
Great solution but its not the actual AppName its a little messier than I'dlike
tigermain
Because you can't change the app name in runtime, this information doesn't need to be in the app itself, but should be determined at compile time. This way, although messier than your 1 line solution, will make your binaries smaller for each target, and essentially make your app a tiny bit faster without the conditionals.
coneybeare
A: 

You can get the app name like this:

NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *theAppName = [info objectForKey:@"CFBundleDisplayName"];
if([theAppName isEqualToString:@"MyAppName"]) {
    //...
}
mrueg
Thanks but theAppName is always NIL
tigermain
Then you should set it in the plist in the bundle
Mark
You could use either CFBundleName or CFBundleExecutable instead of CFBundleDisplayName. With CFBundleExecutable, you should get the same value as ${EXECUTABLE_NAME}.
mrueg
yup CFBundleExecutable did the job nice one thanks
tigermain