Read version from Info.plist
You can read your Info.plist as a dictionary with
[[NSBundle mainBundle] infoDictionary]
And you can easily get the version at the CFBundleVersion
key that way.
Finally, you can get the version with
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];NSString* version = [infoDict objectForKey:@"CFBundleVersion"];
for Swift users:
if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") { print("version is : \(version)")}
for Swift3 users:
if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") { print("version is : \(version)")}
I know that some time has passed since the quest and the answer.
Since iOS8 the accepted answer might not work.
This is the new way to do it now:
NSString *version = (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);