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();