Cocos2d-x dictionaryWithContentsOfFile Fix to read files on IOS

Hi,

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/CCFileUtils_ios.mm
To this:
<pre>
CCDictionary<std::string, CCObject
>**CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char pFileName)
{
//Fix line 1: get the app’s resources path
NSString
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;
}

Hi,

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 http://www.cocos2d-x.org/boards/6/topics/11425 ?

thanks

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