
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the current version of my iOS project in code?
When we build an iOS application, by default it get a version 1.0 and build 0. Whenever we upload a new build to the app store, we need to change the version number. We can update the build number for testing builds. The version and build number are stored in the info.plist file in our project.
Sometimes we might need to access the build or the version number in our application to perform some custom action.
To get the version number we can use the following code and assign it to a variable or constant.
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
To get the build number we can use the below code
Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
For an example, we can use the above code in our viewDidLoad to access these values and print.
override func viewDidLoad() { super.viewDidLoad() let currentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String let currentBuild = Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String print(currentVersion,".",currentBuild) }
When we run the above code we will get our version number followed by a “.” and the build number.
- Related Questions & Answers
- How to get the build/version number of an iOS App?
- How to take a screenshot of my iOS application in the iOS simulator?
- How to get the current location latitude and longitude in iOS?
- How can I get the current Android SDK version programmatically?
- Current Version of CSS
- How to get current date and time from internet in iOS?
- How can I get the current Android SDK version programmatically using Kotlin?
- How to return a string value version of the current number?
- Which version is my MySQL?
- How to detect which iOS version is running on the device?
- How to get current postal code from Network provider in android?
- How to get current country code from Network provider in android?
- How to include CDN Based Version of jQuery in my HTML file?
- Get the hash code for the current Decimal instance in C#
- Get the hash code for the current Int64 instance in C#
Advertisements