Created
May 27, 2015 21:07
-
-
Save Inferis/4bbd3e3f3eda2f90c06d to your computer and use it in GitHub Desktop.
Auto NSCoding?
This file contains hidden or 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
TestModel *model = [TestModel new]; | |
model.aString = @"abc"; | |
model.aDate = [NSDate new]; | |
model.anURL = [NSURL URLWithString:@"http://inferis.org"]; | |
model.subModel = [SubModel new]; | |
model.subModel.aNumber = @123; | |
model.subModel.aValue = [NSValue valueWithCGAffineTransform:CGAffineTransformIdentity]; | |
model.things = @[[SubModel new], [TestModel new]]; | |
model.reference = @{ @"sm": [SubModel new] }; | |
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:model]; | |
TestModel *model2 = [NSKeyedUnarchiver unarchiveObjectWithData:data]; | |
[model isEqual:model2] // true |
This file contains hidden or 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
@interface SubModel : NSObject | |
@property (nonatomic, strong) NSNumber *aNumber; | |
@property (nonatomic, strong) NSValue *aValue; | |
@end | |
@implementation SubModel | |
II_AUTO_NSCODING() | |
@end | |
This file contains hidden or 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
@interface TestModel : NSObject | |
@property (nonatomic, strong, readonly) NSString *suchReadOnly; | |
@property (nonatomic, strong) NSString *aString; | |
@property (nonatomic, strong) NSDate *aDate; | |
@property (nonatomic, strong, getter=getTheURL) NSURL *anURL; | |
@property (nonatomic, assign, setter=setTheBool:) BOOL aBool; | |
@property (nonatomic, assign) NSInteger anInteger; | |
@property (nonatomic, strong) SubModel *subModel; | |
@property (nonatomic, strong) NSArray *things; | |
@property (nonatomic, strong) NSDictionary *reference; | |
@end | |
@implementation TestModel | |
II_AUTO_NSCODING() | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment