Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone: get User Defined variable in Target's setting by code?

My project have multi-targets. Each target has its own Class file for setting stuff. I want to store that Class name in a target setting (Info.plist or Target's Building setting). So that I can define which class I need to use in each target based on this setting.

According to this question, I put "a target-specific User Defined variable" in each Target's Building Setting.

But don't know how to get it back in my code?

like image 474
KONG Avatar asked Jul 23 '10 07:07

KONG


People also ask

How to add user defined build setting Xcode?

Adding User-Defined Build Settings in Xcode To add a user-defined build setting, click the + button at the top and choose Add User-Defined Setting from the list of options. This adds a new build setting to the section of user-defined build settings.

How do I find my target name Swift?

And now in Swift, you may call AppTargetName() and get your target name, without need to modify Info.

Where is target settings in Xcode?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.


1 Answers

As the Info.plist file is preprocessed too, you can use this approach:

Define a User defined setting in your build settings, for Example CLASS_NAME. And a key to your Info.plist-file. Name the key CLASS_NAME and set the value to ${CLASS_NAME}.

You can then access this setting by:

NSString* className = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CLASS_NAME"]; 
like image 76
tonklon Avatar answered Sep 19 '22 11:09

tonklon