Search code examples
iosobjective-carraysdictionaryplist

Array of dict pList returns only indices of Array


I have a plist that looks like this with a count of 81 "dictionary" items:

plist array of 81 dictionary items

I have this code which reads pList into newArray

NSArray *newArray = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"DukeCruiseControlTable" ofType:@"plist"]];

When I look at newArray in the debugger I get:

newArray holds just indices

newArray has the right number of elements, so it is reading the right file. But instead of containing the content of each element it is showing just the index of the element (e.g. [3]).

What am I doing wrong?

Being new to iOS I thought perhaps the debugger just showed me the indices of an Array, but when I use the next code to read the array into another array of objects I get an error that indicates that the newArray element is "[3]" or whatever the index is.

for (dukeperfPerfChartLine *object in newArray)
{
    [self.perfTable addObject:object];
}

Solution

  • I dont see any problem in reading the file, in debugger it will show only the indices, you can try printing the newArray just after reading from the file as:

    NSLog(@"%@",newArray);

    For reading the dictionaries from the newArray,I think you should try this:

    EDITED:

    for (NSDictionary *dict in newArray)
    {
        NSArray *allKeys = [dict allKeys];
        for (NSString *key in allKeys)
        {
            NSLog(@"%@=%@",key,[dict objectForKey:key]); 
        }
    }
    

    Hope it will help.