Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Target name?

We know that Xcode maintains environment variable of ${TARGET_NAME} but how to access this variable in objective-C code ?

What I have tried ?
I have added "TARGET_NAME=${TARGET_NAME}" this in Preprocessor macros section of Build Settings. But now I am not sure how to use this variable "TARGET_NAME" as a string in objective-C code.

In my case product name and target name are different so, no chance to use that.

I tried to access using

#ifdef TARGET_NAME  NSLog(@"TargetIdentifier %@",TARGET_NAME); #endif 

This code is giving error like "Use of undeclared identifier 'myapptargetname'"

like image 239
Iducool Avatar asked Sep 13 '13 09:09

Iducool


People also ask

How do I get my target name Swift?

Add #import "AppTargetName. h" to Obj-c Bridging header (and add/configure it if you don't have one). And now in Swift, you may call AppTargetName() and get your target name, without need to modify Info.


1 Answers

You can add "TargetName" key to your Info.plist file:

enter image description here

Then you can access it (swift code):

var plistFileName = NSBundle.mainBundle().infoDictionary?["TargetName"] as String 
like image 165
Sergey Demchenko Avatar answered Sep 22 '22 22:09

Sergey Demchenko