Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Product version number in swift code

Tags:

xcode

swift

build

Is there's a way to get the product version number inside swift code, like

println("Running version \($PRODUCT_VERSION)")

I have to define some standartUserDefaults, that are bound to the Version and build number and i don't like to put them into my code when it's there at build time.

NSProcessInfo don't have the build number. Any suggestions for me?

like image 849
Peter Shaw Avatar asked Mar 31 '15 07:03

Peter Shaw


People also ask

How do I compare version numbers in Swift?

To compare app version strings, you can use compare(_:options:range:) with an option of . numeric . For brevity, I will create a String extension to wrap compare(_:options:range:) and call it versionCompare(_:) .

What is version and build number?

Generally Version and the build numbers work together to uniquely identify a particular App Store submission for an app. For each new version of your app, you will provide a version number to differentiate it from previous versions. The version number works like a name for each release of your app.


1 Answers

In Swift 5.3:

extension UIApplication {

 static var appVersion: String? {
    return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
 }

}

Usage:

UIApplication.appVersion!
like image 105
Makwan Barzan Avatar answered Sep 17 '22 19:09

Makwan Barzan