Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain bundle identifier programmatically in Swift?

People also ask

How do I get a bundle identifier?

Open you project with XCode, select the top project item in the project navigator at the left. Then select TARGETS -> General. Bundle Identifier is found under Identity.

What is bundle identifier in Swift?

A bundle ID or bundle identifier uniquely identifies an application in Apple's ecosystem. This means that no two applications can have the same bundle identifier. To avoid conflicts, Apple encourages developers to use reverse domain name notation for choosing an application's bundle identifier.


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