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

KONG picture KONG · Jul 23, 2010 · Viewed 19.6k times · Source

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?

Answer

tonklon picture tonklon · Jul 23, 2010

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"];