Created
March 13, 2016 10:10
-
-
Save thii/9409781190ba9bb33f9d to your computer and use it in GitHub Desktop.
Safe way to get current app version and build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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