NSUserDefaults enables quick access to small data

Source: Internet
Author: User

Usage reason: the data is single, small, and the code is concise.

I. Position of NSUserDefaults Data Storage

NSUserDefaults is used to save iPhone program data, which is very convenient to use.
So where will the data be stored? Stored in a plist file.
This file is located in <UUID for your App> LibraryPreferences <your App "s bundle ID>. plist

2. supported data types
NSUserDefaults only supports: NSString, NSNumber, NSDate, NSArray, NSDictionary.

Iii. Fetch
For example:
Objective-c code
// Read and save the number of times users use the software

NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];

NSNumber * count = [ud objectForKey: @ "times"];


Iv. Storage

Example:
Objective-c code
Int t = [count intValue] + 1;

[Ud setObject: [NSNumber numberWithInt: t] forKey: @ "times"];

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.