Let make your code be complicated…
struct Version {
let short: String
let full: String
let display: String
}
And make an extension for UIApplication
:
extension UIApplication {
static var version: Version {
let short = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
let full = NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String
let display = full.containsString(".") ? full : "\(short).\(full)"
return Version(short: short, full: full, display: display)
}
}
Your time:
debugPrint(UIApplication.version.short)
debugPrint(UIApplication.version.full)
debugPrint(UIApplication.version.display)