Skip to content

Instantly share code, notes, and snippets.

@alexpaul
Last active June 10, 2020 20:58
Show Gist options
  • Save alexpaul/de85efd8710053a1b6c96f46491ef904 to your computer and use it in GitHub Desktop.
Save alexpaul/de85efd8710053a1b6c96f46491ef904 to your computer and use it in GitHub Desktop.
Get the version and build number for your app. This is especially useful to track version / builds on the AppStore / TestFlight.
import Foundation
class ApplicationInfo {
class func getVersionBuildNumber() -> String {
guard let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString"),
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
else {
fatalError("no version info")
}
return "\(version) (\(build))"
}
class func getAppName() -> String {
guard let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String else {
fatalError("what? no app name")
}
return appName
}
}
/*
If you're missing this CFBundleDisplayName add the following to the Info.plist
<key>CFBundleDisplayName</key>
<string>CareerView</string>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment