QuickTip Series #3

Get application informations like app version

Goal

Display the application version within the app.

Tip

Simply access the main bundle info dictionary with Bundle.main.infoDictionary. You can print this array and see all the information specified in your info.plist.

Example

For example if you want to print the app version and build version (i.e 1.0.0(1)):

func getAppVersion(infoDictionary: [String : Any]? = Bundle.main.infoDictionary) -> String? {
    if let dict = infoDictionary {
        if let version = dict["CFBundleShortVersionString"] as? String,
            let bundleVersion = dict["CFBundleVersion"] as? String {
	         return "\(version)(\(bundleVersion))"
        }
    }
    return nil
}

print(getAppVersion()) // => will display 1.0.0(0)

Simple!