Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the name of the target that is currently running in Xcode?

Tags:

xcode

ios

build

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.

like image 925
Enrico Susatyo Avatar asked Apr 21 '16 02:04

Enrico Susatyo


People also ask

How do I access targets in Xcode?

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.

How do I change my target name in Xcode?

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.

How do I find my target Swift?

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.


1 Answers

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
like image 91
Niko Adrianus Yuwono Avatar answered Sep 30 '22 15:09

Niko Adrianus Yuwono