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:
- The list of attributes is ideal for storing lightweight local data
- Data formats that support storage are data types in the foundation framework Nsnumber,nsstring,nsdate,nsarray,nsdictionary,bool, 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 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:
- 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----