Created
May 14, 2024 07:27
-
-
Save kovs705/e639576a9c04ccf7d8622d161919632b to your computer and use it in GitHub Desktop.
iOS App Info
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
/// Wrapper to get some app related strings at one place. | |
struct AppInfo { | |
/// Returns the official app name, defined in your project data. | |
var appName: String { | |
return readFromInfoPlist(withKey: "CFBundleName") ?? "(unknown app name)" | |
} | |
/// Return the official app display name, eventually defined in your 'infoplist'. | |
var displayName: String { | |
return readFromInfoPlist(withKey: "CFBundleDisplayName") ?? "(unknown app display name)" | |
} | |
/// Returns the official version, defined in your project data. | |
var version: String { | |
return readFromInfoPlist(withKey: "CFBundleShortVersionString") ?? "(unknown app version)" | |
} | |
/// Returns the official 'build', defined in your project data. | |
var build: String { | |
return readFromInfoPlist(withKey: "CFBundleVersion") ?? "(unknown build number)" | |
} | |
/// Returns the bundle identifier String. | |
var bundleIdentifier: String { | |
return Bundle.main.bundleIdentifier ?? "Unknown bundle identifier" | |
} | |
/// Returns the minimum OS version defined in your project data. | |
var minimumOSVersion: String { | |
return readFromInfoPlist(withKey: "MinimumOSVersion") ?? "(unknown minimum OSVersion)" | |
} | |
/// Returns the copyright notice eventually defined in your project data. | |
var copyrightNotice: String { | |
return readFromInfoPlist(withKey: "NSHumanReadableCopyright") ?? "(unknown copyright notice)" | |
} | |
/// Returns the official bundle identifier defined in your project data. | |
// var bundleIdentifier: String { | |
// return readFromInfoPlist(withKey: "CFBundleIdentifier") ?? "(unknown bundle identifier)" | |
// } | |
var developer: String { return "my awesome name" } | |
// MARK: - Info plist | |
/// A reference to the Info.plist of the app as Dictionary | |
private let infoPlistDictionary = Bundle.main.infoDictionary | |
/// Retrieves and returns associated values (of Type String) from info.Plist of the app. | |
private func readFromInfoPlist(withKey key: String) -> String? { | |
return infoPlistDictionary?[key] as? String | |
} | |
// MARK: - App scheme | |
func isDebug() -> Bool { | |
#if DEBUG | |
return true | |
#else | |
return false | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment