Skip to content

Commit

Permalink
Minor style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Feb 10, 2014
1 parent cf3bb6e commit df03aa9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 6 additions & 4 deletions Mantle/MTLJSONAdapter.m
Expand Up @@ -108,15 +108,17 @@ - (id)initWithJSONDictionary:(NSDictionary *)JSONDictionary modelClass:(Class)mo


id value = JSONDictionary; id value = JSONDictionary;
NSArray *JSONKeyPathComponents = [JSONKeyPath componentsSeparatedByString:@"."]; NSArray *JSONKeyPathComponents = [JSONKeyPath componentsSeparatedByString:@"."];
for (NSString *itemJSONKeyPathComponent in JSONKeyPathComponents) { for (NSString *itemJSONKeyPathComponent in JSONKeyPathComponents) {
if (![value isKindOfClass:NSDictionary.class]) { if (![value isKindOfClass:NSDictionary.class]) {
if (error != NULL) { if (error != NULL) {
NSDictionary *userInfo = @{ NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid JSON dictionary", @""), NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid JSON dictionary", @""),
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"%@ could not be created because an invalid JSON dictionary was provided for keypath: %@", @""), NSStringFromClass(modelClass), JSONKeyPath], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"%@ could not be parsed because an invalid JSON dictionary was provided for key path \"%@\"", @""), modelClass, JSONKeyPath],
}; };

*error = [NSError errorWithDomain:MTLJSONAdapterErrorDomain code:MTLJSONAdapterErrorInvalidJSONDictionary userInfo:userInfo]; *error = [NSError errorWithDomain:MTLJSONAdapterErrorDomain code:MTLJSONAdapterErrorInvalidJSONDictionary userInfo:userInfo];
} }

return nil; return nil;
} }


Expand Down
9 changes: 4 additions & 5 deletions MantleTests/MTLJSONAdapterSpec.m
Expand Up @@ -74,12 +74,11 @@
}); });


it(@"should return nil and error with an invalid key path from JSON",^{ it(@"should return nil and error with an invalid key path from JSON",^{

NSDictionary *values = @{ NSDictionary *values = @{
@"username": @"foo", @"username": @"foo",
@"nested": @"bar", @"nested": @"bar",
@"count": @"0" @"count": @"0"
}; };


NSError *error = nil; NSError *error = nil;
MTLTestModel *model = [MTLJSONAdapter modelOfClass:MTLTestModel.class fromJSONDictionary:values error:&error]; MTLTestModel *model = [MTLJSONAdapter modelOfClass:MTLTestModel.class fromJSONDictionary:values error:&error];
Expand Down

0 comments on commit df03aa9

Please sign in to comment.