Get App Name in Swift

后端 未结 17 2004
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 00:20

How do I get the application name in Swift?

Googling gave me this:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@\"CFBundleName\"];
         


        
17条回答
  •  不知归路
    2020-12-24 00:53

    simple way:

    let appName = NSBundle.mainBundle().infoDictionary?[kCFBundleNameKey as String] as? String
    

    convenient way:

    extension NSBundle {
        class func mainInfoDictionary(key: CFString) -> String? {
            return self.mainBundle().infoDictionary?[key as String] as? String
        }
    }
    print(NSBundle.mainInfoDictionary(kCFBundleNameKey))
    

    kCFBundleNameKey – Standard Info.plist key, see more in CFBundle

提交回复
热议问题