How do I get the App version and build number using Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In iOS app development, it's often necessary to retrieve versioning details of an app programmatically. This often includes the app's version number (e.g. 1.0.0) and build number (e.g. 100). These are typically set within the app's Info.plist file. Having access to these properties can be critical, especially for debugging, user feedback, and analytics.
In this article, you'll learn how to extract the app version and build number using Swift. You'll be introduced to technical concepts and code examples that demonstrate how to achieve this in a standard iOS app.
Understanding CFBundleShortVersionString and CFBundleVersion
Before diving into code, it's important to understand two key properties from the app's Info.plist file:
- CFBundleShortVersionString: This is a user-facing version number (e.g., 1.0.0), representing the release version of the app.
- CFBundleVersion: This is the build number (e.g., 100), typically used for internal reference to track builds.
Both properties are string types and are required to uniquely identify a specific version of the app.
Retrieving Version and Build Number
Accessing the Info.plist
The app's version and build number are defined in the Info.plist file. To access these values programmatically in Swift, you can use the Bundle class, specifically the main bundle associated with your application.
Here's how you can access these values:
Explanation
- Bundle.main: Represents the top-level directory where the app resources are located.
- infoDictionary: A dictionary containing the key-value pairs listed in the Info.plist file.
- Subscripts ["CFBundleShortVersionString"] and ["CFBundleVersion"]: Used to retrieve specific values from the
infoDictionary.
Using the Version and Build Number
Displaying in UI
You might want to display this information within the app interface, particularly in settings or help screens:
Sending to Server
For debugging and analytics, you might need to send this information to a server:
Summary
Here's a concise table summarizing how to access the version and build number:
| Property | Key | Description | Example Value |
| Version Number | CFBundleShortVersionString | User-facing version number | 1.0.0 |
| Build Number | CFBundleVersion | Internal build reference number | 100 |
| Retrieval Class | Bundle.main | Info.plist access agent inside the app | - |
| Retrieval Method | infoDictionary? | Method to access plist key-value pairs | - |
Conclusion
Accessing the app version and build number is a simple yet crucial task in iOS development. It allows developers to manage releases efficiently and improve user experience by providing important metadata for troubleshooting and feature updates. By implementing the strategies outlined in this guide, you can reliably retrieve this information and utilize it for various purposes within your app.

