📜  swift get app version and build - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:03.239000             🧑  作者: Mango

代码示例2
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