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: