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?
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.
And now in Swift, you may call AppTargetName() and get your target name, without need to modify Info.
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.
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"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With