0

I have a property list that has a dictionary at the root and 21 arrays as rows,ordered by their corresponding key. Each key has array (value) of 8 strings. Something like this:

  Root                     Dictionary       (21 items)
  "#14"                     Array           (8 items)   
  "#12"                     Array           (8 items)
    Item 0                  String           0.164
    Item 1                  String           0.123
    item 2                  String           0.211

.... so on

in my implementation file, I have:

`- (void)loadTable9NECWithBundle:(NSBundle *)bundle {

   bundle = [NSBundle mainBundle] ;
    if (bundle != nil)
    {
  /* Read the cable table data from the disk in a dictionary of arrays. Each array contains >       only one cable size data. */
      NSString *CableData = [bundle pathForResource:@"Table9-NEC" ofType:@"plist"];
       NSDictionary *tableDict = [NSDictionary dictionaryWithContentsOfFile:CableData];
       NSString *datos = nil;
       NSEnumerator *enumerator = [tableDict keyEnumerator];
       id key;
       while ((key = [enumerator nextObject]))
       {
       oneCableSizeDataArray = [[NSMutableArray alloc] initWithObjects:[tableDict >     valueForKey:key] ,nil];
       NSLog(@"key is %@ ", key);
          datos = [oneCableSizeDataArray objectAtIndex: 0 ];
           NSLog(@"value is %@ ", datos);

      }

The console show clearly that I could iterate trough all keys correctly, however the array oneCableSizeDataArray get the value as a single string, not a 8 string as in the plist file representation., it means [oneCableSizeDataArray count] returns 1. (single object).

I can not figure out why this is happening. Any help is appreciated.

4

1 回答 1

1

I'm not on the Mac I'm doing iOS development on right now, but from what I remember you don't want to use dictionaryWithContentsOfFile, you want to use propertyListWithData:options:format:error: as otherwise it won't load the nested properties correctly. The result of that message can be assigned to an NSDictionary object and accessed as you would normally. (Speaking of that, the more recent versions of Xcode support more succinct indexing and key access, such as oneCableSizeDataArray[0] and tableDict["#14"].)

于 2013-06-13T19:32:55.067 回答