+5  A: 

Look into your Info.plist file which should have keys like CFBundleVersion and CFBunldeShortVersion

Eimantas
More info:http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-102364http://www.dribin.org/dave/blog/archives/2006/08/02/versioning_os_x_apps/
cpharmston
ghommey - there's a guide for list programming on developer.apple.com. I'm sure you can find that out by yourself now ,)
Eimantas
+2  A: 

After further searching and testing I could find the solution by myself.

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSLog(@"%i Keys:  ", [infoDictionary count],
             [[infoDictionary allKeys] componentsJoinedByString: @" ,"]);

This snipplet gave me the following output:

20 Keys : NSBundleResolvedPath ,CFBundleVersion ,NSBundleInitialPath ,CFBundleIdentifier ,NSMainNibFile ,CFBundleIconFile ,CFBundleInfoPlistURL ,CFBundleExecutable ,DTSDKName ,UIStatusBarStyle ,CFBundleDevelopmentRegion ,DTPlatformName ,CFBundleInfoDictionaryVersion ,CFBundleSupportedPlatforms ,CFBundleExecutablePath ,CFBundleDisplayName ,LSRequiresIPhoneOS ,CFBundlePackageType ,CFBundleSignature ,CFBundleName

So the solution is as simple as:

NSString *version =[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];

However this is not the Current Project Version as seen in the screenshot but the Bundle Version of the plist file.

Ghommey
I think then versioning includes adding repositories and setting up SCM for your project in XCode and that's probably not the version you want (although i may be wrong).
Eimantas
A: 

Those items in the Build Info are not available to your built app. They are placeholders that you could possibly pull into your app. What is in your app is anything that you place in, say, the Resources folder of your app, like any text files, or plists, or a nice picture of your versioning engineer.

Now, you could pull some of the items in the Build Info window into a info.plist, using special identifiers, such as ${VERSION_INFO_PREFIX} or other token. The tokens are available if you click on any of the items on the left hand side in the window you have included above. For example, click on the word "Current Project Version" and copy the token that you see at the bottom, "CURRENT_PROJECT_VERSION". Then go to your plist file, and add an entry. Give it any name you want or "Current Project Version". Paste in ${CURRENT_PROJECT_VERSION} on the right hand side. Now that value is available to you from your app, programmatically. Of course, someone now has to enter that value into the appropriate place either in the Build Info window or elsewhere. It might just be easier just to manage this and fields like this in the info.plist file. It's up to you how you'd like to handle these things.

Here is how I get version info out of my info.plist:

+ (NSString *) getAppVersionNumber;
{
    NSString *myVersion,
       *buildNum,
       *versText;

    myVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    buildNum = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
    if (myVersion) {
     if (buildNum)
      versText = [NSString stringWithFormat:@"Version: %@ (%@)", myVersion, buildNum];
     else
      versText = [NSString stringWithFormat:@"Version: %@", myVersion];
    }
    else if (buildNum)
     versText = [NSString stringWithFormat:@"Version: %@", buildNum];
    NSLog(versText);
    return versText;
}
mahboudz
"Undefined or garbage value returned to caller"! Delete versText and put a return statement on it's position. At the end return nil.
testing