iOS Archive solution

Source: Internet
Author: User

. h file

#import <foundation/foundation.h>typedef Void (^myblock) (NSData *); typedef ns_enum (Nsinteger, cylgender) {    Cylgendermail,    Cylgenderfemale}; @interface user:nsobject<nscopying,nsmutablecopying, nscoding>{    unsigned int count;} @property (nonatomic, ReadWrite, copy) NSString *name; @property (nonatomic, ReadWrite, assign) Nsuinteger age; @property ( Nonatomic, ReadWrite, assign) Cylgender gender;
@end

. m file

#import "User.h" #import <objc/runtime.h> @interface User () @end @implementation User@synthesize FirstName = _ firstName; @synthesize lastName = _lastname;    -(instancetype) init{self = [super init]; if (self) {} return to self;} -(Instancetype) Initwithname: (NSString *) name Age: (Nsuinteger) Age Gender: (CYL    Gender) Gender {self = [super init];        if (self) {_name = name;        _age = age;    _gender = gender; } return self;} -(void) Addfriend: (user *) User {[_friends addobject:user];} -(void) Removefriend: (user *) User {[_friends removeobject:user];} -(ID) Copywithzone: (Nszone *) Zone {User *copy = [[[Self class] allocwithzone:zone] initwithname:_name age:_age Gender:    _gender];    Copy--_friends = [_friends mutablecopy]; return copy;} -(ID) deepcopy {User *copy = [[[Self class] alloc] Initwithname:_name a                                         Ge:_age    Gender:_gender];    copy-_friends = [[Nsmutableset alloc] Initwithset:_friends Copyitems:yes]; return copy;} -(ID) Mutablecopywithzone: (Nszone *) Zone {User *copy = [[[Self class] allocwithzone:zone] Initwithname:_name age:_age    Gender:_gender];    Copy--_friends = [_friends mutablecopy]; return copy;}    #pragma mark-de-instancetype-(Initwithcoder): (Nscoder *) adecoder {unsigned int outcount;        if (self = = [Super init]) {objc_property_t * Objs = Class_copypropertylist ([self class], &outcount);            for (int i =0; i < Outcount; i++) {objc_property_t obj = objs[i];            NSString *name = [nsstring stringwithutf8string:property_getname (obj)];            ID value = [adecoder decodeobjectforkey:name];        [Self setvalue:value forkey:name];        } free (OBJS); Ivar *ivars = Class_copyivarlist ([self class], &outcount);//for (int i =0; i < outcount; i + +) {/ /Ivar Ivar = ivars[i];//nsstring *keyname = [NSString stringwithutf8string:ivar_getname (Ivar)];//id value = [a]    Decoder decodeobjectforkey:keyname];//[self setvalue:value forkey:keyname];//}//free (ivars); } return self;}    #pragma mark-Archive-(void) Encodewithcoder: (Nscoder *) acoder {unsigned int outcount;    objc_property_t *OBJCS = Class_copypropertylist ([self class], &outcount);        for (int i=0; i<outcount; i++) {objc_property_t OBJC = objcs[i];        NSString *name = [NSString stringwithutf8string:property_getname (OBJC)];        ID value = [self valueforkey:name];    [Acoder Encodeobject:value Forkey:name];        } free (OBJCS); Ivar *ivars = Class_copyivarlist ([self class], &outcount);//for (int i =0; I <outCount; i++) {//I var ivar = ivars[i];//NSString *keyname = [NSString stringwithutf8string:ivar_getname (Ivar)];//if ([Keynam e isequaltostring:[self Ignoreparameter]]) {//            continue;//}//id value = [self valueforkey:keyname];//[acoder encodeobject:value Forke y:keyname];//}//Free (ivars);
}

  

iOS Archive solution

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.