Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Inferis
Created May 27, 2015 21:07
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 Inferis/4bbd3e3f3eda2f90c06d to your computer and use it in GitHub Desktop.
Save Inferis/4bbd3e3f3eda2f90c06d to your computer and use it in GitHub Desktop.
Auto NSCoding?
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
@interface SubModel : NSObject
@property (nonatomic, strong) NSNumber *aNumber;
@property (nonatomic, strong) NSValue *aValue;
@end
@implementation SubModel
II_AUTO_NSCODING()
@end
@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