Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created February 12, 2016 18:02
Show Gist options
  • Select an option

  • Save mingsai/0daf7f20b3e72824d3f8 to your computer and use it in GitHub Desktop.

Select an option

Save mingsai/0daf7f20b3e72824d3f8 to your computer and use it in GitHub Desktop.
A Swift extension to provide application version numbers and commonly used global constants
//
// MNGApplicatioNExtensions.swift
//
//
// Created by Tommie N. Carter, Jr., MBA on 6/22/15.
// Copyright © 2015 MING Technology. All rights reserved.
//
import UIKit
import iAd
let userdefaults = NSUserDefaults.standardUserDefaults()
let defaultCenter = NSNotificationCenter.defaultCenter()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
extension UIApplication {
private struct Constants {
static let CFBundleShortVersionString = "CFBundleShortVersionString"
}
class func appVersion() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey(Constants.CFBundleShortVersionString) as! String
}
class func appBuild() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String
}
class func versionBuild() -> String {
let version = appVersion(), 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