Skip to content

Instantly share code, notes, and snippets.

@ethanmick
Created April 21, 2014 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanmick/11144101 to your computer and use it in GitHub Desktop.
Save ethanmick/11144101 to your computer and use it in GitHub Desktop.
// header.h
@interface CMTestEncoderNSCoding : NSObject <NSCoding>
@property (nonatomic, copy) NSString *aString;
@property (nonatomic, assign) NSInteger anInt;
@end
@interface CMTestEncoderNSCodingParent : CMObject
@property (nonatomic, strong) CMTestEncoderNSCoding *something;
@end
// .m
@implementation CMTestEncoderNSCoding
- (id)initWithCoder:(NSCoder *)aDecoder;
{
if ( self = ([super init]) ) {
self.aString = [aDecoder decodeObjectForKey:@"aString"];
self.anInt = [aDecoder decodeIntegerForKey:@"anInt"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder;
{
[aCoder encodeObject:self.aString forKey:@"aString"];
[aCoder encodeInteger:self.anInt forKey:@"anInt"];
}
@end
@implementation CMTestEncoderNSCodingParent
- (id)initWithCoder:(NSCoder *)aDecoder;
{
if ( self = ([super initWithCoder:aDecoder]) ) {
self.something = [aDecoder decodeObjectForKey:@"something"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder;
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:self.something forKey:@"something"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment