Make a Custom Class Serializable in Objective-c/iPhone? -
How do I serialize my own custom class? I especially want to write it to a file on iPhone, just plist and you class is just a simple example class, just NSStrings and maybe an NSUrl.
You would like to apply InitWithCoder to implement: and EncoderCoder: and your custom class with NSKeyedArchiver and NSKeyedUnarchiver Will work.
Your initWithCoder: should look like this:
- (id) initWithCoder: (NSCoder *) AdCoder {if (Self = [Super Invite]) / / This [ Super Init With Coder: ADCoder], superclass nsciding {astring = [[adcoder decode objectwork: @ "estring"] is to be maintained; Other string = [[Adicoder decode objectForcae: @ "other string"] retained]; } Healthy return; }
and encoded code:
- (zero) encoded codec: (encoder *) add encoder {// [Super encode codec: encoder] Superclass applies encoding [encoder encoded object: astringe fork: @ "estring"]; [Encoder encoded object: other string fork: @ "other string"]; }
Comments
Post a Comment