How to get Target name? How to get Target name? xcode xcode

How to get Target name?


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


NSLog(@"Target name: %@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]);

Hope to help you!

Edited: "CFBundleName" thanks Max and Daniel Bo for your commend


Swift 4, Xcode 9+

Bundle name:

Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""

Bundle display name:

Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? ""

Swift 3, Xcode 8+

let targetName = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? ""