UserDefault

cocos2d-x 3.9

UserDefault可以作为一个小的数据存储库,它能够保存和获取基本的数据类型。

它支持存储以下的基本数据类型:
bool, int, float, double, string

包含的函数如下:

//----get类型方法
//根据key值获取对应的value值,如果值不存在,无默认值则返回false,提供默认值则返回默认值

//bool型
bool getBoolForKey(const char* key);
virtual bool getBoolForKey(const char* key, bool defaultValue);

 //整型
int getIntegerForKey(const char* key);
 virtual int getIntegerForKey(const char* key, int defaultValue);

 //float
float   getFloatForKey(const char* key); 
virtual float getFloatForKey(const char* key, float defaultValue);

 //double
 double  getDoubleForKey(const char* key);
 virtual double getDoubleForKey(const char* key, double defaultValue);

 //string
 std::string getStringForKey(const char* key);
 virtual std::string getStringForKey(const char* key, const std::string & defaultValue);

 //data
 Data getDataForKey(const char* key);
 virtual Data getDataForKey(const char* key, const Data& defaultValue);

//----set类型方法
//设置key和对应的value值
virtual void setBoolForKey(const char* key, bool value);
virtual void setIntegerForKey(const char* key, int value);
virtual void setFloatForKey(const char* key, float value);
virtual void setDoubleForKey(const char* key, double value);
virtual void setStringForKey(const char* key, const std::string & value);
virtual void setDataForKey(const char* key, const Data& value);

//set方法设置value之后,提交保存数据()
virtual void flush();

//根据key值删除数据
virtual void deleteValueForKey(const char* key);

//获取xml数据的存储路径
 static const std::string& getXMLFilePath();

/** All supported platforms other iOS & Android and CC_PLATFORM_WINRT use xml file to save values. This function checks whether the xml file exists or not.
 * @return True if the xml file exists, false if not.
 * @js NA
 */
 //xml数据文件是否存在
static bool isXMLFileExist();

//获取实例
static UserDefault* getInstance();
//摧毁实例
static void destroyInstance();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值