The way to get the value from plist

I have an integer NumberX and plist called PlistX.

Example

int NumberX; 

PlistX:

plist

I was wondering how I would make NumberX = Three

+6
source share
2 answers

Try the following:

 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); 
+15
source

1) Get data (i.e. NSMutableDictionary * ) from plist saved to disk:

 NSMutableDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:NULL errorDescription:&error]; 

2) Extract the required object from the dictionary.

 //in your case NSNumber *tmpNumber = [[[dictionary objectForKey:@"One"] objectForKey:@"Two"] objectForKey:@"Three"]; // convert to int int NumberX = [tmpNumber intValue]; 
+3
source

Source: https://habr.com/ru/post/914397/


All Articles