Obtain bundle identifier programmatically in Swift?

前端 未结 3 1190
旧时难觅i
旧时难觅i 2020-12-30 18:11

How can I get the bundle ID in Swift?

Objective-C version:

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
3条回答
  •  太阳男子
    2020-12-30 18:49

    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

提交回复
热议问题