Skip to content

Instantly share code, notes, and snippets.

@thii
Created March 13, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thii/9409781190ba9bb33f9d to your computer and use it in GitHub Desktop.
Save thii/9409781190ba9bb33f9d to your computer and use it in GitHub Desktop.
Safe way to get current app version and build
import Foundation
struct AppVersion {
static func version() -> String? {
return NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as? String
}
static func build() -> String? {
return NSBundle.mainBundle().infoDictionary?["CFBundleVersion"] as? String
}
static func fullVersionString() -> String? {
guard let version = version() else { return nil }
guard let build = build() else { return version }
return "\(version) (\(build))"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment