List of properties in iOS----

Source: Internet
Author: User

A property list, which is a file used to store serialized objects. Because the extension is plist, it is often referred to as a plist file.

plist files are typically used to store user settings or to store bundled information in XML format. It can be dynamically created and read and written during the run of a program, so it can be used for data persistence in small amounts of data.

The Nsuserdefaults class provides a programming interface for interacting with the default system, which allows users to read and write data while the program is running, enabling data persistence. The file used to store Nsuserdefaults is essentially a property list file.

< a > Custom attribute list access
//Get file pathNSString *documentpath =[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) lastobject]; NSString*filepath = [Documentpath stringbyappendingpathcomponent:@"student.plist"]; //data stored in the plist fileNsmutabledictionary *dict =[Nsmutabledictionary dictionary]; Nsdictionary*stu1= @{@"Idnum":@"1",@"name":@"Jereh"}; [Dict setvalue:stu1 Forkey:@"STU1"];//new data is written to the plist file[Dict Writetofile:filepath Atomically:yes]; //reading data from a plist fileNsmutabledictionary *dicnow =[[Nsmutabledictionary alloc] initwithcontentsoffile:filepath];intIdnum = [[Dicnow objectforkey:@"Idnum"] intvalue]; NSString*name = [Dicnow objectforkey:@"name"];

Summary:

    1. The list of attributes is ideal for storing lightweight local data
    2. Data formats that support storage are data types in the foundation framework Nsnumber,nsstring,nsdate,nsarray,nsdictionary,bool, NSData
    3. The property list cannot store custom objects,
    4. The root directory of a property list can be nsdictionary or Nsarray only
    5. Stored as key-value pairs
    6. Storage time is the overall application duration, and if you want to delete it, you need to delete the whole application
< two > Nsuserdefaults
  //Create a Nsuserdefaults objectNsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; //Save Data[Defaults setobject:@"Jereh"Forkey:@"name"]; //storing data from the cache on disk[Defaults synchronize]; //Fetch DataNSString *name = [Defaults objectforkey:@"name"]; //Delete Data[Defaults Removeobjectforkey:@"name"]; [Defaults synchronize];

Summary:

    1. Nsuserdefaults is ideal for storing lightweight local data
    2. Data formats that support storage are data types in the foundation framework
    3. Cannot store custom objects
    4. Stored as key-value pairs
    5. Storage time is the overall application duration, and if you want to delete it, you need to delete the whole application

List of properties in iOS----

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.