I have a integer called NumberX and a plist called PlistX.
Example
int NumberX;
PlistX:
I was wondering how I'd make NumberX = value of Three
Try this:
NSString *path = [[NSBundle mainBundle] pathForResource:@"PlistX" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
int number = [[[[dict objectForKey:@"One"] objectForKey:@"Two"]objectForKey:@"Three"] intValue];
NSLog(@"%d",number);
1) Get data (i.e. NSMutableDictionary *
) from plist saved to disk:
NSMutableDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:NULL errorDescription:&error];
2) Retrieve needed object from dictionary.
//in your case
NSNumber *tmpNumber = [[[dictionary objectForKey:@"One"] objectForKey:@"Two"] objectForKey:@"Three"];
// convert to int
int NumberX = [tmpNumber intValue];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With