Read dictionary from plist file preserving keys order.

I’m reading dictionary from plist file:

myDict = CCDictionary::dictionaryWithContentsOfFile (...)

And when I get an array of all dictionary keys (myDict->allKeys())
they are rearranged (seems because of hashing).

Is there a way to keep order of keys such as that was in plist file?

Hi…

may I ask u How you doing this, CCDictionary from a plist…

I tried this…

CCDictionary<std::string,CCObject*> *plistDictionary = CCDictionary::dictionaryWithContentsOfFile( fileName );

but I’m getting an error " Expected a class or namespace "

I’m trying to create a dictionary of english words…

can u post the code you r using and the format of the data in the plist file….

I believe that’ll help … :smiley:

Thanks…

Dinesh Balu
Looks like you don’t use cocos2d namespace. Try add USING_NS_CC; at the beginning of your source file.

Volodymyr Ivanyshyn wrote:

Looks like you don’t use cocos2d namespace. Try add USING_NS_CC; at the beginning of your source file.

I do use cocos2d namespace and I added USING_NS_CC; also…

didn’t work… same error…

can u give me an working example…?

Thanks

Dinesh Balu
I don’t have separate example of it (in my case I’m modifying cocos2d engine to read plist file).
But you can take a look at CCSpriteFrameCache::addSpriteFramesWithFile (...) in CCSpriteFrameCache.cpp - dictionary is reading there (and I’m modifying that piece of code).

>Volodymyr Ivanyshyn wrote:

I don’t have separate example of it (in my case I’m modifying cocos2d engine to read plist file).
But you can take a look at CCSpriteFrameCache::addSpriteFramesWithFile (...) in CCSpriteFrameCache.cpp - dictionary is reading there (and I’m modifying that piece of code).

Oh… k then I’ll check that…

have u found any solution to ur problem…?

Only workaround: I additionally keep array of dictionary keys in plist file, and after reading the dictionary I read this array (its items preserve order).
But I’m still looking for approach without additional array.

Nice… atleast its working for u…

This was the most recommended result when I searched for plist reading and I tried this also

CCDictionary < std::string,CCObject* > *plistDictionary = CCFileUtils::dictionaryWithContentsOfFile ( "3LetterWords.plist" ) ;

and this is how my plist file looks like

`<?xml version="1.0" encoding="UTF-8"?>

ROOT aah aah aal aal aas aas aba aba `

when i print the count with CCLOG it prints 0… u know why…?

Is that the corrent format of plist file…