Created
April 21, 2014 14:20
-
-
Save ethanmick/11144101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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