getting the dictionary keys and values in unordered form
NSData* myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
wTimerId = 99;
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 96;
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedSho开发者_StackOverflowrt:wTimerId]];
wTimerId = 97;
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 98;
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 95;
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
I'm storing the data with the key value in the order 99,96,97,98,95. But it gets stored as
{
98 = <b0c71000 01000000>;
97 = <b0c71000 01000000>;
96 = <b0c71000 01000000>;
99 = <b0c71000 01000000>;
95 = <b0c71000 01000000>;
}
why is it so.Is there any way to arrange the dictionary in the way which gets stored first.
Dictionaries are inherently unordered. If you want order, use an array.
If you want both order and key based lookup, store both the array and dictionary; one to preserve order, the other to preserve key based lookup.
Just keep 'em in sync.
精彩评论