Cocos2d-x dictionaryWithContentsOfFile Fix to read files on IOS

Cocos2d-x dictionaryWithContentsOfFile Fix to read files on IOS
0.0 0



I was having trouble to read .plist files on ios and after spending a few hours on it, i became with a fix.

So basically you have to change this method

CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe
Located in cocos2d-x/platform/ios/
To this:
CCDictionary<std::string, CCObject
>**CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char pFileName)
//Fix line 1: get the app’s resources path
plistFilePath = [[NSBundle mainBundle] resourcePath];
NSString* pPath = [NSString stringWithUTF8String:pFileName];
//Fix line 2, change the pPath for the resourcePath+pFileName
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:"%/%s",plistFilePath,pFileName]];

CCDictionary<std::string, CCObject*>* pRet = new CCDictionary<std::string, CCObject*>();
for (id key in [pDict allKeys]) {
id value = [pDict objectForKey:key];
static_addValueToCCDict(key, value, pRet);

return pRet;



I have a basic problem with plist. I cannot parse a foo plist file but it’s not a path problem.

Can you give a look at ?



i have left a reply in your original post, hope that it helps you. :slight_smile: