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 path NSString *documentpath = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) Lastobject]; NSString *filepath = [documentpath stringbyappendingpathcomponent:@ "Student.plist"]; Data stored in the plist file nsmutabledictionary *dict = [Nsmutabledictionary dictionary]; Nsdictionary *stu1= @{@ "idnum": @ "1" @ "name": @ "Jereh"}; [Dict setvalue:stu1 forkey:@ "STU1"];//new data written to plist file [Dict writetofile:filepath atomically:yes]; Read the data in the plist file nsmutabledictionary *dicnow = [[Nsmutabledictionary alloc] initwithcontentsoffile:filepath];int idNum = [[Dicnow objectforkey:@ "Idnum"] intvalue]; NSString *name = [dicnow objectforkey:@ "name"];
Summary:
- The list of attributes is ideal for storing lightweight local data
- The data format that supports storage is the data type Nsnumber,nsstring,nsdate,nsarray,nsdictionary,bool in the foundation framework, NSData
- The property list cannot store custom objects,
- The root directory of a property list can be nsdictionary or Nsarray only
- Stored as key-value pairs
- Storage time is the overall application duration, and if you want to delete it, you need to delete the whole application
< two > Nsuserdefaults
Create Nsuserdefaults object nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults]; Save Data [Defaults setobject:@ "Jereh" forkey:@ "name"]; Storing the data in the cache on disk [defaults synchronize]; Fetch data nsstring *name = [Defaults objectforkey:@ "name"]; Delete Data [defaults removeobjectforkey:@ "name"]; [Defaults synchronize];
Summary:
- Nsuserdefaults is ideal for storing lightweight local data
- Data formats that support storage are data types in the foundation framework
- Cannot store custom objects
- Stored as key-value pairs
- 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----