Last active
February 22, 2021 20:30
-
-
Save konnnn/86c2dabdcef080f399e3ee3817a343fc to your computer and use it in GitHub Desktop.
App information such as app name, app version, etc.
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
// App information such as app name, app version, etc. | |
// AppInfo.swift | |
// Created by Evgeny Konkin on 23.02.2021. | |
// | |
import Foundation | |
struct AppInfo { | |
private static func dictionary(key string: String) -> String? { | |
return Bundle.main.infoDictionary?[string] as? String | |
} | |
static var appName: String { | |
return self.dictionary(key: "CFBundleName") ?? "(unknown app name)" | |
} | |
static var appDisplayName: String { | |
return self.dictionary(key: "CFBundleDisplayName") ?? "(unknown app name)" | |
} | |
static var version: String { | |
return self.dictionary(key: "CFBundleShortVersionString") ?? "(unknown version)" | |
} | |
static var build: String { | |
return self.dictionary(key: "CFBundleVersion") ?? "(unknown build)" | |
} | |
static var minOSVersion: String { | |
return self.dictionary(key: "MinimumOSVersion") ?? "(unknown min OS version)" | |
} | |
static var copyrightNotice: String { | |
return self.dictionary(key: "NSHumanReadableCopyright") ?? "(unknown copyright notice)" | |
} | |
static var bundleIdentifier: String { | |
return self.dictionary(key: "CFBundleIdentifier") ?? "(unknown bundle identifier)" | |
} | |
static var developer: String { | |
return "Developer Name" | |
} | |
} | |
// Usage example | |
print("App version", AppInfo.version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment