class Info {
static let dictionary = Bundle.main.infoDictionary ?? [:]
enum Value {
case build, version
}
}
extension Info.Value {
var key: String {
switch self {
case .build: return kCFBundleVersionKey as String
case .version: return kCFBundleInfoDictionaryVersionKey as String
}
}
var string: String? { return Info.dictionary[key] as? String }
}
用法
if let value = Info.Value.version.string { print("Version: \(value)") }
if let value = Info.Value.build.string { print("Build: \(value)") }