Obtain bundle identifier programmatically in Swift?

醉酒当歌 提交于 2019-11-30 07:47:34
Sebastian

Try this:

let bundleID = NSBundle.mainBundle().bundleIdentifier

Swift 3+:

let bundleID = Bundle.main.bundleIdentifier

It's pretty much the same thing in Swift except the class and method names have been shortened:

let bundleIdentifier = Bundle.main.bundleIdentifier // return type is String?

If you are trying to get it programmatically , you can use below line of code :

Objective-C:

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

Swift 3.0:

let bundleIdentifier =  Bundle.main.bundleIdentifier

Updated for latest swift It will work for both iOS and Mac apps.

For More Info, Check here :

Apple Docs: https://developer.apple.com/documentation/foundation/bundle#//apple_ref/occ/instm/NSBundle/bundleIdentifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!