I have an Xcode project with several targets. Let's say the target names are AppFreeVersion
and AppPaidVersion
. They share the same codebase, but I want to implement some logic that is only for one of the targets.
Without modifying my scheme or build settings, is there a way to get the string of my current target name? The solution given in this question requires me to pass an environment variable in the build setting, which I don't want to do.
You can access Target Membership by selecting file and opening the right menu in Xcode (the menu is called Inspectors ). Then, in File Inspector at the bottom of the menu, find Target Membership . It's very important to check all files in your project because without this you won't be able to build a new app target.
Rename the Target to Rename the App Select the project from the project navigator to open the project editor and see a list of the app's targets. To rename a target, select it, press the Return key, and enter the new name. If all you want to do is rename the app, you're finished.
In Xcode, go into the build configuration for a target. Find the section called Swift Compiler - Custom Flags, which contains a setting called Other Swift Flags.
How about adding ${TARGET_NAME}
in your info.plist?
And I guess you already know how to get it
Obj-C
[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];
Swift
let targetName = NSBundle.mainBundle().infoDictionary?[key_name] as String
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