Get App Name in Swift

后端 未结 17 1820
被撕碎了的回忆
被撕碎了的回忆 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:52

    // Returns app's name

    public static var appDisplayName: String? {
        if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
            return bundleDisplayName
        } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
            return bundleName
        }
        return nil
    }
    

提交回复
热议问题