@@ -70,10 +70,8 @@ +(void)load
7070
7171 // This is quite strange, but I found the test isSubclassOfClass: (line ~291) to fail if using [JSONModel class].
7272 // somewhat related: https://stackoverflow.com/questions/6524165/nsclassfromstring-vs-classnamednsstring
73- // //NSClassFromString(@"JSONModel"); seems to break the unit tests
74- if (!JSONModelClass) {
75- JSONModelClass = [JSONModel class ];
76- }
73+ // //; seems to break the unit tests
74+ JSONModelClass = [JSONModel class ];
7775 }
7876 });
7977}
@@ -316,7 +314,8 @@ -(id)initWithDictionary:(NSDictionary*)dict error:(NSError**)err
316314
317315
318316 // 1) check if property is itself a JSONModel
319- if ([[property.type class ] isSubclassOfClass: JSONModelClass]) {
317+
318+ if ([self __isJSONModelSubClass: property.type]) {
320319
321320 // initialize the property's model, store it
322321 JSONModelError* initErr = nil ;
@@ -446,6 +445,17 @@ -(id)initWithDictionary:(NSDictionary*)dict error:(NSError**)err
446445}
447446
448447#pragma mark - property inspection methods
448+
449+ -(BOOL )__isJSONModelSubClass : (Class )class
450+ {
451+ // http://stackoverflow.com/questions/19883472/objc-nsobject-issubclassofclass-gives-incorrect-failure
452+ #ifdef UNIT_TESTING
453+ return [@" JSONModel" isEqualToString: NSStringFromClass ([class superclass ])];
454+ #else
455+ return [class isSubclassOfClass: JSONModelClass];
456+ #endif
457+ }
458+
449459// returns a set of the required keys for the model
450460-(NSMutableSet *)__requiredPropertyNames
451461{
@@ -654,7 +664,7 @@ -(id)__transform:(id)value forProperty:(JSONModelClassProperty*)property error:(
654664 }
655665
656666 // if the protocol is actually a JSONModel class
657- if ([[protocolClass class ] isSubclassOfClass: JSONModelClass ]) {
667+ if ([self __isJSONModelSubClass: protocolClass ]) {
658668
659669 // check if it's a list of models
660670 if ([property.type isSubclassOfClass: [NSArray class ]]) {
@@ -733,7 +743,7 @@ -(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)property
733743 if (!protocolClass) return value;
734744
735745 // if the protocol is actually a JSONModel class
736- if ([[protocolClass class ] isSubclassOfClass: JSONModelClass ]) {
746+ if ([self __isJSONModelSubClass: protocolClass ]) {
737747
738748 // check if should export list of dictionaries
739749 if (property.type == [NSArray class ] || property.type == [NSMutableArray class ]) {
0 commit comments