i have a plist which goes like this:
<dict>
<key>11231654</key>
<array>
<string>hello</string>
<string>goodbye</string>
</array>
<key>78978976</key>
<array>
<string>ok</string>
<string>cancel</string>
</array>
i've load the plist using this:
NSString *path = [[NSBundle mainBundle] pathForResource:
@"data" ofType:@"plist"];
// Build the array from the plist
NSMutableArray *array3 = [[NSMutableArray alloc] initWithContentsOfFile:path];
how can i access each element of my plist? i want to search for a matching key in the plist and than search with its child. how can i do this? any suggestion?
thks in advance!
Arrays are indexed. If you wanted to access the first object in an NSArray
, you’d do the following:
id someObject = [array objectAtIndex:0];
If you know the object type, you could do it like this:
NSString *myString = [array objectAtIndex:0];
EDIT: You need to use an NSDictionary
for the data that you have—note that it starts with a <dict>
tag, not an <array>
tag (though there are arrays as values).
NSString *path = [[NSBundle mainBundle] pathForResource:
@"data" ofType:@"plist"];
// Build the array from the plist
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *value = [dict valueForKey:@"11231654"];
Now you can do whatever you want with your array.
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