首页 > 代码库 > cocos2d-x CCDictionary的遍历

cocos2d-x CCDictionary的遍历

CCDictionary的遍历不是用for或foreach,而是cocos2d-x自己封装了一个遍历方法CCDICT_FOREACH(__dict__, __el__)

用法:

CCDictionary * pDict = CCDictionary::create();

pDict->setObject(CCString::create("value1"), "key1");

pDict->setObject(CCString::create("value2"), "key2");

CCDictElement * pElement;

CCDICT_FOREACH(pDict, pElement)

{

const char * key = pElement->getStrKey();

CCString * value = http://www.mamicode.com/(CCString *)pElement->getObject();

CCLog(key);

CCLog(value ->getCString());

}

cocos2d-x CCDictionary的遍历