/*1. Add the Address Book class (name, phone) to the archive and archive method, that is, add the method that stores the information to the disk. */
#import <Foundation/Foundation.h>
#import "ConTact.h"
#define PATH @ "/users/qianfeng/desktop/hehe/2.plist"
int main (int argc, const char * argv[]) {
@autoreleasepool {
Contact *contact = [[Contact alloc] init];
Contact.name = @ "Xiaowang";
Contact.tel = @ "135";
Creating a mutable binary file
Nsmutabledata *mdata = [[Nsmutabledata alloc] init];
Create an Archive object
Nskeyedarchiver *keyarchiver = [[Nskeyedarchiver alloc]initforwritingwithmutabledata:mdata];
Archived objects
[Keyarchiver encodeobject:contact forkey:@ "name"];
Complete archiving
[Keyarchiver finishencoding];
Write file
[Mdata Writetofile:path Atomically:yes];
printf ("...... ..... ..... ..... ..... .....)..............
To read a binary file
NSData *data = [[NSData alloc] initwithcontentsoffile:path];
Create a solution Archive object
Nskeyedunarchiver *keyunarchiver = [[Nskeyedunarchiver alloc] initforreadingwithdata:data];
Solution Archive
Contact *c = [keyunarchiver decodeobjectforkey:@ "name"];
Release Archive
[Keyunarchiver finishdecoding];
NSLog (@ "%@,%@", C.name,c.tel);
}
return 0;
}
Add the Address Book class (name, phone), archive and archive method, that is, add the method of storing information to disk.