Read version from Info.plist

后端 未结 5 1490
北荒
北荒 2021-01-30 02:49

I want to read the bundle version info from Info.plist into my code, preferably as a string. How can I do this?

5条回答
  •  佛祖请我去吃肉
    2021-01-30 03:27

    for Swift users:

    if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") {
        print("version is : \(version)")
    }
    

    for Swift3 users:

    if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") {
        print("version is : \(version)")
    }
    

提交回复
热议问题