UserDefault

来源:互联网 发布:阿里云 地区选择 编辑:程序博客网 时间:2024/05/29 12:13

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); //floatfloat   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
原创粉丝点击