Swift Pobierz wersję aplikacji i zbuduj
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
Valentino_Rossi
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
import Foundation
extension Bundle {
var shortVersion: String {
if let result = infoDictionary?["CFBundleShortVersionString"] as? String {
return result
} else {
assert(false)
return ""
}
}
var buildVersion: String {
if let result = infoDictionary?["CFBundleVersion"] as? String {
return result
} else {
assert(false)
return ""
}
}
var fullVersion: String {
return "\(shortVersion)(\(buildVersion))"
}
}
// Usage:
someLabel.text = Bundle.main.versionNumber
import Foundation
let versionString = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "Default String to shut up warning"
let buildString = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "Default String to shut up warning"