开发者

NSDictionary dictionaryWithContentsOfFile doesnt load the data in order

I am trying to load some data fr开发者_如何学Pythonom a plist into an array

NSDictionary* mydictionary = [ NSDictionary dictionaryWithContentsOfFile:[ [ [ NSBundle      mainBundle] bundlePath ] stringByAppendingPathComponent:@"MyLevels.plist" ] ];

NSMutableArray *panelNames1;                                                         
panelNames1 = [[NSMutableArray alloc] init];

for (id theKey in mydictionary) {        
    [panelNames1 addObject:[mydictionary objectForKey:theKey]]; 
}

But it does not seem to output in the same order as the MyLevels.plist into the array.

MyLevels.plist looks likes this: [Key:1 Value: One] [Key:2 Value: Two] [Key:3 Value: Three] [Key:4 Value: Four] [Key:5 Value: Five]

But it reads it in this order: Three, One, Four, Two, Five

Any idea why?? Or even another way of doing the for loop maybe so it is in the correct order.

Thanks


NSDictionary objects do not preserve ordering. You should not expect to have keys enumerated in the same order in which they were read.


If order is important, you should create an array in your plist, and access it from one of the dictionary keys.


Any idea why?

Yes. NSDictionary is unordered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜