您的位置:首页 > 其它

UserDefault

2015-07-30 17:51 357 查看
CCLOG("********************** init value ***********************");
// set default value
UserDefault::getInstance()->setStringForKey("string", "value1");
UserDefault::getInstance()->setIntegerForKey("integer", 10);
UserDefault::getInstance()->setFloatForKey("float", 2.3f);
UserDefault::getInstance()->setDoubleForKey("double", 2.4);
UserDefault::getInstance()->setBoolForKey("bool", true);

// print value

std::string ret = UserDefault::getInstance()->getStringForKey("string");
CCLOG("string is %s", ret.c_str());

double d = UserDefault::getInstance()->getDoubleForKey("double");
CCLOG("double is %f", d);

int i = UserDefault::getInstance()->getIntegerForKey("integer");
CCLOG("integer is %d", i);

float f = UserDefault::getInstance()->getFloatForKey("float");
CCLOG("float is %f", f);

bool b = UserDefault::getInstance()->getBoolForKey("bool");
if (b)
{
CCLOG("bool is true");
}
else
{
CCLOG("bool is false");
}

//CCUserDefault::getInstance()->flush();

CCLOG("********************** after change value ***********************");

// change the value

UserDefault::getInstance()->setStringForKey("string", "value2");
UserDefault::getInstance()->setIntegerForKey("integer", 11);
UserDefault::getInstance()->setFloatForKey("float", 2.5f);
UserDefault::getInstance()->setDoubleForKey("double", 2.6);
UserDefault::getInstance()->setBoolForKey("bool", false);

UserDefault::getInstance()->flush();

// print value

ret = UserDefault::getInstance()->getStringForKey("string");
CCLOG("string is %s", ret.c_str());

d = UserDefault::getInstance()->getDoubleForKey("double");
CCLOG("double is %f", d);

i = UserDefault::getInstance()->getIntegerForKey("integer");
CCLOG("integer is %d", i);

f = UserDefault::getInstance()->getFloatForKey("float");
CCLOG("float is %f", f);

b = UserDefault::getInstance()->getBoolForKey("bool");
if (b)
{
CCLOG("bool is true");
}
else
{
CCLOG("bool is false");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: