Attribute List in IOS ---- Property List, ios ---- property

Source: Internet
Author: User

Attribute List in IOS ---- Property List, ios ---- property

Attribute list is a file used to store serialized objects. Because the extension is plist, it is usually called a plist file.

Plist files are usually used to store user settings, and can also be used to store bundled information. The content is in xml format. It can be dynamically created and read/write during the running of the program, so it can be used for data persistence when a small amount of data is running.

The NSUserDefaults class provides a programming interface for interacting with the default system. You can read and write data while running the program, achieving data persistence. The file used to store NSUserDefaults is essentially an attribute list file.

<1> access to a custom property list
// Obtain the file path NSString * documentPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString * filePath = [documentPath stringByAppendingPathComponent: @ "student. plist "]; // NSMutableDictionary * dict = [NSMutableDictionary dictionary]; NSDictionary * stu1 =@{ @" idNum ": @" 1 ", @ "name": @ "jereh"}; [dict setValue: stu1 forKey: @ "stu1"]; // write new data to the plist file [dict writeToFile: filePath atomically: YES]; // read data in plist files. NSMutableDictionary * dicNow = [[NSMutableDictionary alloc] initWithContentsOfFile: filePath]; int idNum = [[dicNow objectForKey: @ "idNum"] intValue] NSString * name = [dicNow objectForKey: @ "name"];

Summary:

<2> NSUserDefaults
// Create the NSUserDefaults object NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; // Save the data [defaults setObject: @ "jereh" forKey: @ "name"]; // store the cached data on the disk [defaults synchronize]; // obtain the data NSString * name = [defaults objectForKey: @ "name"]; // Delete the data [defaults removeObjectForKey: @ "name"]; [defaults synchronize];

Summary:

Related Article

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.