How to add and get the values from .plist in iOS How to add and get the values from .plist in iOS objective-c objective-c

How to add and get the values from .plist in iOS


Here is a code sample:

NSString *path = [[NSBundle mainBundle] pathForResource: @"YourPLIST" ofType: @"plist"]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];id obj = [dict objectForKey: @"YourKey"];


NSBundle* mainBundle = [NSBundle mainBundle]; 

 

// Reads the value of the custom key I added to the Info.plistNSString *value = [mainBundle objectForInfoDictionaryKey:@"key"];//Log the valueNSLog(@"Value = %@", value);

// Get the value for the "Bundle version" from the Info.plist[mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];// Get the bundle identifier[mainBundle bundleIdentifier];


NSURL *url = [[NSBundle mainBundle] URLForResource:@"YOURPLIST" withExtension:@"plist"];NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];NSLog(@"Here is the Dict %@",playDictionariesArray);

or you can use following also

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Sample.plist"];