This method is based on the last one of the methods made some changes, more convenient.
Since the code inside the new class has not changed, it is no longer written here.
Optimization Benefits: At the beginning of the definition of a macro, the path is placed directly in the macro here, if you want to change the address later, directly change the macro definition of OK.
#import<Foundation/Foundation.h>#import "Human.h"#definePATH @ "/users/cain/desktop/objective-c/Experiment code/File operation/Archive/human/human.txt"intMainintargcConst Char*argv[]) {@autoreleasepool {Human*human1 =[[Human alloc]init]; Human*human2 =[[Human alloc]init]; Human1.age= -; Human1.name=@"xiaoming"; Human1.child=human2; NSData*data1 =[Nskeyedarchiver Archiveddatawithrootobject:human1]; [Data1 Writetofile:path Atomically:yes]; NSLog (@"%@", data1); } return 0;}
The use of nscoding---archiving on your Mac (optimized edition).