When developing your iOS or Mac app, you might find it useful to reference the app's version number within your code. This could be useful for a number of reasons, such as sending version info alongside analytics data or even just to display the current version to the user on your settings or preferences page.
To get the app's version string (e.g. v3.5.0
), you can use the following code:
Bundle.main.infoDictionary?["CFBundleShortVersionString"]
If you want the specific build number (e.g. 254
), you can instead add:
Bundle.main.infoDictionary?["CFBundleVersion"]
Depending on your use-case it might be useful to get just one or both of these values.