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'"
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.
You can add "TargetName" key to your Info.plist file:
Then you can access it (swift code):
var plistFileName = NSBundle.mainBundle().infoDictionary?["TargetName"] 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