iOS app, programmatically get build version
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
On iOS, the build version and the marketing version are not the same thing. If you want to show version info in a debug screen, attach it to bug reports, or log it at startup, you usually read CFBundleVersion for the build number and CFBundleShortVersionString for the user-facing release version.
Read Version Values From Info.plist
The app bundle exposes its metadata through Bundle.main. The keys you usually want are:
- '
CFBundleVersionfor the build number' - '
CFBundleShortVersionStringfor the release version'
In Swift:
This is the most direct way to access the values that Xcode writes into the app bundle.
Wrap the Logic in a Helper
Instead of scattering string keys around the app, wrap them in a small helper:
This makes it easy to reuse the information in settings screens, support emails, diagnostics, and crash reports.
Show It in SwiftUI or UIKit
For SwiftUI:
For UIKit:
The values are static for the running build, so reading them once and exposing them through a helper is usually enough.
Understand the Difference Between Build and Release Version
Developers often mix these values up:
- '
CFBundleShortVersionStringis what users think of as the app version, such as2.4.1' - '
CFBundleVersionis the internal build number, such as2410'
The App Store expects the build number to increase for each uploaded build of a given release version. That is why support teams often ask for both values rather than only one.
Objective-C Version
If you are maintaining older iOS code, the same data is available in Objective-C:
The source is the same Info.plist; only the syntax changes.
Make It Visible in Diagnostics
Reading the values is only half the job. The real benefit comes when you include them in places where support and engineering can actually see them, such as:
- An in-app debug screen
- Startup logs
- Crash-report metadata
- Support emails generated from the app
That makes it much easier to distinguish "the user is on release 2.3" from "the user is on build 2415 of release 2.3."
Common Pitfalls
- Reading only
CFBundleShortVersionStringwhen you really need the internal build number makes bug reports less precise. - Hardcoding version strings in UI code guarantees they will drift from the actual app metadata.
- Misspelling the
Info.plistkeys returnsnil, so wrap access safely. - Assuming TestFlight, App Store, and local debug builds all share the same versioning behavior can create confusion if the build number is not being incremented properly in Xcode or CI.
Summary
- Use
Bundle.mainto read version metadata fromInfo.plist. - '
CFBundleVersionis the build number;CFBundleShortVersionStringis the release version.' - Wrap the lookup in a helper so the app uses one consistent source of truth.
- Show both values when you need support-friendly diagnostics.
Related reading
- iOS app submission missing 64-bit support
- iOS app 'The application could not be verified' only on one device
- iOS app with framework crashed on device, dyld Library not loaded, Xcode 6 Beta
- iOS app with framework crashed on device, dyld Library not loaded, Xcode 6 Beta
- iOS autolayout to center my view between two views
- iOS Autolayout two buttons of equal width, side by side
- iOS Build Failed at compile time with issue failed to find a suitable device for the type SimDeviceType
- iOS change navigation bar title font and color
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.