How do I get the current version of my iOS project in code?

后端 未结 8 1323
挽巷
挽巷 2020-12-12 10:23

I would like to be able to get the current version of my iOS project/app as an NSString object without having to define a constant in a file somewhere. I don\'t

相关标签:
8条回答
  • 2020-12-12 11:12

    In Swift, you can get bundle version by using:

    let info:NSDictionary = NSBundle.mainBundle().infoDictionary!
    
    let version:String = info.objectForKey("CFBundleShortVersionString") as! String
    
    versionLabel.text = "Version:" + version
    
    0 讨论(0)
  • 2020-12-12 11:12

    So heres a Swift version for both of these separately:

    let versionNumber = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
    let buildNumber = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion") as! String
    

    Its included in this repo, check it out:

    https://github.com/goktugyil/EZSwiftExtensions

    0 讨论(0)
提交回复
热议问题