Getting iOS app version programmatically

Getting the version string and the build number, in Objective-C, Swift, and C# (Xamarin)

Use CFBundleVersion for the build number instead of the string.

Swift

let versionStr = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
let versionNum = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "" // Yes, the version number is also a String
let version = String(format: "%@-%@", versionStr, versionNum)

Objective-C

let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary["CFBundleShortVersionString"]
let version = nsObject as String

C#

NSObject ver = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"];