File manipulation of data localization

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.