Recently, a project in the request data is slow, the interface is very unfriendly, and then want to store the last request data, when the interface to display the last data, and then when the data request is completed and then the data refresh
I am not familiar with the data operation, the new person can refer. On the Internet to see the iOS data localization method, I chose the Nsuserdefaults method and file writing method
First, Nsuserdefaults
The Nsuserdefaults method is very simple, get the Nsuserdefaults object, and then the dictionary operation is almost
Deposit data
[[Nsuserdefaults standarduserdefaults]setobject:dic forkey:@ "infor"];//deposited dic data in a infor-key data
[[Nsuserdefaults Standarduserdefaults]synchronize];//nsuserdefaults is timed to store the file, synchronize method is to manually make the file storage operations immediately
The object being deposited is the basic data type of Apple native, such as NSString, NSNumber, NSDate, Nsarray, Nsdictionary, BOOL, Nsinteger, nsfloat, etc., if the verse is empty, the Nsnull object, Then it will be an error, if the error can be checked to see if the data is empty. If you want to deposit objects, you can convert the data to NSData data and then use the
-(void) SetObject: (nullable ID) value Forkey: (NSString *) DefaultName;
This method deposits data into
Remove data
Nsdictionary *getdic = [[Nsuserdefaults standarduserdefaults]objectforkey:@ "infor"];
The method of extracting the data is similar to the dictionary, which takes out the data stored by a key.
Nsuserdefaults suitable for storing some small, commonly used data, such as login name, login password, key and other data
File manipulation of data localization