Understanding PLIST files

Understanding PLIST files
0.0 0



I have a published simple game in App Store using Cocos2D framework.

Now I’m trying to export it to Android, and the best option I have found is obviously Cocos2D-X. I have been implementing some screens successfully, but now I cannot continue and don’t know what is the problem.

I’m trying to read a plist which contains the game data. I have created the following plist which is a simple implementation of the real one:


<?xml version="1.0" encoding="UTF-8"?> testitems name Test1 height 480 name Test2 height 500 name Test3 height 420 name Test4 height 360 @

Now if I try the following, I expect in LogCat “Count: 4”, but the fact is I get a random number in each execution… What I’m doing wrong??

CCDictionary<std::string, CCObject*> plistDictionary = CCFileUtils::dictionaryWithContentsOfFile;
testitems = (CCArray*)plistDictionary->objectForKey(“testitems”);
CCLog(“COUNT: %d”, testitems->count());

Thanks in advance!




Hi Jordi, I’m having a problem exactly as you described, did you resolve it?



Hi Tom,

the problem was trying to use a CCArray object. Here it works a bit different. What did work for me was changing the previous code by this:

CCDictionary<std::string, CCObject*> *plistDictionary = CCFileUtils::dictionaryWithContentsOfFile;
>*testitems = (CCMutableArray<CCObject>*)plistDictionary->objectForKey(“testitems”);
CCLog(“COUNT: %d”, testitems->count());

You must change “CCArray**" by "CCMutableArray<CCObject*>**”.


Well, it seems it has been a problem with the formatting, let’s try again:

CCDictionary<std::string, CCObject*> *plistDictionary = CCFileUtils::dictionaryWithContentsOfFile("testplist.plist"); CCMutableArray<CCObject*> *testitems = (CCMutableArray<CCObject*>*)plistDictionary->objectForKey("testitems"); CCLog("COUNT: %d", testitems->count());


Hey, that worked. Thanks very much for speedy reply :slight_smile:

Not sure why mutable is required, but never mind!


We have created a PLIST video series PLIST Video Tutorial