Access data plist

I have a plist that looks 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 downloaded 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 every element of my layer? I want to find the appropriate key in plist and search with my child. How can i do this? any suggestion?

thks in advance!

+5
source share
3 answers

Arrays are indexed. If you want to access the first object in NSArray, you must do the following:

id someObject = [array objectAtIndex:0];

If you know the type of object, you can do it like this:

NSString *myString = [array objectAtIndex:0];

EDIT: NSDictionary , , - , <dict>, <array> ( ).

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"];

, , .

+8

, , . @Jeff Kelley , , . , !

+1

plist

plist screenshot

, . plist.

NSString *pathOfPlist = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
arrPlistValue = [[NSArray alloc]initWithContentsOfFile:path];
NSLog(@"Plist Value : %@",arrPlistValue);

:

NSString *strName = [[arrTempValue objectAtIndex:0] objectForKey:@"name"];
NSString *strImage = [[arrTempValue objectAtIndex:0] objectForKey:@"image"];
int idValue = [[[arrTempValue objectAtIndex:0] objectForKey:@"id"] integerValue];
BOOL isSubCat = [[[arrTempValue objectAtIndex:0] objectForKey:@"isSubCategory"] boolValue];

, string, boolean plist.!

+1
source

All Articles