The use of nscoding---archiving on your Mac (optimized edition).

Source: Internet
Author: User

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).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.