How to programmatically display version/build number of target in iOS app?

后端 未结 6 1659
广开言路
广开言路 2020-12-04 05:16

How can I programmatically get the value of the target version, like in the image below?

As seen in the Properties window of the target of my Xcode proj

6条回答
  •  温柔的废话
    2020-12-04 06:08

    You don't need to change anything in your project or Xcode. Here's the Swift version for both separately:

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

    It's included in this repo, check it out:

    https://github.com/goktugyil/EZSwiftExtensions

提交回复
热议问题