icanzilb/JSONModel — pull request #174 by BillinghamJ (2014-02-23 11:27:07+00:00)
Title: Implementation of NSCopying

Initial implementation of NSCopying protocol, as discussed in #44

Do not consider merging yet - this is not ready & there are no unit tests. Just opening for discussion first.

One issue has come to mind with this. I believe there will be a failure in the following use case:

Example Model:

@interface MyModel : JSONModel

@property (strong, nonatomic) NSString *recipient;
@property (strong, nonatomic) NSString *subject;
@property (strong, nonatomic) NSString *message;

@end

Example code:

- (void)myMethod
{
MyModel *model = [[MyModel alloc] init];
model.recipient = @"bob@example.com";
model.subject = @"Foobar Asdf";

MyModel *duplicateModel = model.copy;
model.subject = @"Blah blah";
}

JSONModel will throw an error on the `model.copy`, because a required property is null. This happens because of the use of the `initWithDictionary:error:` method.

It is (in my opinion) 100% valid to want to copy an incomplete model.

I propose that we add initialization functions where validation can be disabled. I know this is going to be a bit of a pain to implement, but I think it'd be valuable elsewhere also.

Let me know what you think, or if you need any clarifications.