Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Created June 12, 2019 17:51
Show Gist options
  • Select an option

  • Save rsaenzi/4f4c346d4b5f2b23611b862628cacdc2 to your computer and use it in GitHub Desktop.

Select an option

Save rsaenzi/4f4c346d4b5f2b23611b862628cacdc2 to your computer and use it in GitHub Desktop.
Functions to get the version and build numbers in an iOS app
//
// UIApplication+AppVersion.swift
//
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/)
// Copyright © 2019. All rights reserved.
//
import UIKit
extension UIApplication {
class func appVersion() -> String {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}
class func appBuild() -> String {
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
}
class func versionBuild() -> String {
let version = appVersion()
let build = appBuild()
return version == build ? "v\(version)" : "v\(version) (\(build))"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment