Monday, April 29, 2013

NSBundle objectForInfoDictionaryKey example ios


objectForInfoDictionaryKey:

Returns the value associated with the specified key in the receiver's information property list.
- (id)objectForInfoDictionaryKey:(NSString *)key
Parameters
key
A key in the receiver's property list.
Return Value of [NSBundle objectForInfoDictionaryKey]
The value associated with key in the receiver's property list (Info.plist). The localized value of a key is returned when one is available.
Discussion
Use of this method is preferred over other access methods because it returns the localized value of a key when one is available.
Example of [NSBundle objectForInfoDictionaryKey] - 1
+ (NSString *) appVersion
{
    return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];    
}

+ (NSString *) build
{
    return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
}

Example of [NSBundle objectForInfoDictionaryKey] - 2
NSBundle *bundle = [NSBundle mainBundle];   
NSString *appVersion = [bundle objectForInfoDictionaryKey:(NSString *)@"CFBundleShortVersionString"];
NSString *appBuildNumber = [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];