Skip to content

Instantly share code, notes, and snippets.

@licvido
Last active December 31, 2019 00:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save licvido/4e4633c8ea119e92e359 to your computer and use it in GitHub Desktop.
Save licvido/4e4633c8ea119e92e359 to your computer and use it in GitHub Desktop.
SWIFT: Get application version and build
let version : AnyObject! = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString")
let build : AnyObject! = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion")
println("Version: \(version)")
println("Build: \(build)")
@iballan
Copy link

iballan commented Jun 5, 2017

// Swift 3
extension Bundle {
  var versionNumber: String? {
    return infoDictionary?["CFBundleShortVersionString"] as? String
  }
  var buildNumber: String? {
    return infoDictionary?["CFBundleVersion"] as? String
  }
}

@johnyu0424
Copy link

johnyu0424 commented Feb 10, 2018

// Swift 4
let version : Any! = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
let build : Any! = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")

print("Version: \(version)")
print("Build: \(build)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment