Test archive and archive intelmail
# Import "ViewController. h"
# Import "dog. h"
@ Interface ViewController ()
@ End
@ Implementation ViewController
// Store data
-(IBAction) writeDataAction :( UIButton *) sender {
// 1. Obtain the storage path
NSString * documents = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString * filePath = [documents stringByAppendingPathComponent: @ "data. plist"];
// 2. Create an object
Dog * superDog = [[dog alloc] init];
SuperDog. name = @ "wangcai ";
SuperDog. age = 18;
SuperDog. isTrue = YES;
// 3. Archive NSKeyedArchive
// If archive is used, the archived object must comply with the NSCoding protocol and encoding protocol.
[NSKeyedArchiver archiveRootObject: superDog toFile: filePath];
NSLog (@ "% @", filePath );
}
// Read data
-(IBAction) readDataAction :( UIButton *) sender {
// 1. Obtain the storage path
NSString * documents = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString * filePath = [documents stringByAppendingPathComponent: @ "data. plist"];
// Retrieve the stored object
Dog * superDog = [NSKeyedUnarchiver unarchiveObjectWithFile: filePath];
NSLog (@ "% @ years old ??? ===%@ ", SuperDog. name, @ (superDog. age), @ (superDog. isTrue ));
}