Prior to the use of archived technology in the project, also used in the Mjextension
But the problem is, this public library encountered some problems can not be archived, so that the egg pain, how to do it.
For the parts that cannot be archived, the function is manually archived, very silent.
Find out why:
Originally for two models, how a inherits B, then A has a big situation is unable to archive!
Wrote it myself.
For the A model and the B-mode above, the definition is as follows:
#import <Foundation/Foundation.h> #import "Student.h" @interface Coder:nsobject@property (nonatomic,copy) NSString *text; @property (nonatomic,copy) nsstring *username; @property (nonatomic,copy) nsstring *classid; @property ( Nonatomic,strong) Student *stu; @end
Its archive should be written in the following form:
-(void) Encodewithcoder: (Nscoder *) acoder{ [Acoder encodeobject:_classid forkey:@ "ClassId"]; [Acoder encodeobject:_username forkey:@ "UserName"]; [Acoder encodeobject:_text forkey:@ "text"]; [Acoder encodeobject:_stu forkey:@ "Stu"]; } -(ID) Initwithcoder: (Nscoder *) Adecoder//ns_designated_initializer{ _classid = [Adecoder decodeobjectforkey:@] ClassId "]; _username = [Adecoder decodeobjectforkey:@ "UserName"]; _text = [Adecoder decodeobjectforkey:@ "text"]; _stu = [Adecoder decodeobjectforkey:@ "Stu"]; return self;}
The B model is defined as follows:
#import "Coder.h" @interface Coderchild:coder@property (nonatomic, strong) NSString *king; @property (nonatomic, Strong) NSString *father; @end
Its archive is written in the following form:
-(void) Encodewithcoder: (Nscoder *) acoder{ [Super Encodewithcoder:acoder]; [Acoder encodeobject:_king forkey:@ "King"]; [Acoder encodeobject:_father forkey:@ "father"];} -(ID) Initwithcoder: (Nscoder *) Adecoder//ns_designated_initializer{ unsigned int count = 0; self = [super Initwithcoder:adecoder]; if (self) { _king = [Adecoder decodeobjectforkey:@ "King"]; _father = [Adecoder decodeobjectforkey:@ "father"]; } return self;}
Above two classes, subclass to invoke the Initwithcoder method of the parent class
Otherwise, the attributes in the negative class cannot be archived.
An archive implementation of the inherited object model in iOS