0.0 0


I want to know how to setobject in UserDefault .Like in cocos2d we have [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];

Thanks in advance…


Do you mean this?


Check out the class reference:



no , my question is different. read carefully…


pankaj khanduja wrote:

no , my question is different. read carefully…

You didn’t check the class reference, then:
>It supports the following base types: bool, int, float, double, string

Apparently, there isn’t an equivalent to setObject.


bro that what i am asking…NSUserdefault has method setobject()….and also want to setObject in CCUserdefault but there is no such method…any alternative to access the object using key value…


Sorry, your english is a bit confusing.
I’m guessing you want something like CCDictionary, then. You can store a pointer to an object and retrieve it by key:

// Create a dictionary, return an autorelease object.
CCDictionary* pDict = CCDictionary::create();
// Insert objects to dictionary
CCString* pValue1 = CCString::create("100");
CCString* pValue2 = CCString::create("120");
CCInteger* pValue3 = CCInteger::create(200);
pDict->setObject(pValue1, "key1");
pDict->setObject(pValue2, "key2");
pDict->setObject(pValue3, "key3");
// Get the object for key
CCString* pStr1 = (CCString*)pDict->objectForKey("key1");
CCLog("{ key1: %s }", pStr1->getCString());
CCInteger* pInteger = (CCInteger*)pDict->objectForKey("key3");
CCLog("{ key3: %d }", pInteger->getValue());



sorry for bad english…
you create dictionary for storing the objects into it but now i want to store that dictinary in userdefault so that i can access that dictionary any other scene using its key value…


For what I understand, that is not possible with CCUserDefault.
I’ve seen people do something similar to what you want by creating their own classes/singletons, though. Shouldn’t be that hard: create the class, instance it once and access the one instance to get the data you want from a CCDictionary.