@@ -365,11 +365,36 @@ +(id)objectOfClass:(Class)objectClass fromJSON:(NSDictionary *)dict {
365365
366366-(NSString *)classOfPropertyNamed : (NSString *)propName {
367367 objc_property_t theProperty = class_getProperty ([self class ], [propName UTF8String ]);
368- NSString *className = [NSString stringWithFormat: @" %s " , getPropertyType (theProperty)];
369- return className;
368+
369+ const char *attributes = property_getAttributes (theProperty);
370+ char buffer[1 + strlen (attributes)];
371+ strcpy (buffer, attributes);
372+ char *state = buffer, *attribute;
373+ while ((attribute = strsep (&state, " ," )) != NULL ) {
374+ if (attribute[0 ] == ' T' && attribute[1 ] != ' @' ) {
375+ // it's a C primitive type:
376+ /*
377+ if you want a list of what will be returned for these primitives, search online for
378+ "objective-c" "Property Attribute Description Examples"
379+ apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc.*/
380+ NSString *typeName = [[NSString alloc ] initWithData: [NSData dataWithBytes: (attribute + 1 ) length: strlen (attribute) - 1 ] encoding: NSUTF8StringEncoding];
381+ return typeName;
382+ }
383+ else if (attribute[0 ] == ' T' && attribute[1 ] == ' @' && strlen (attribute) == 2 ) {
384+ // it's an ObjC id type:
385+ return @" id" ;
386+ }
387+ else if (attribute[0 ] == ' T' && attribute[1 ] == ' @' ) {
388+ // it's another ObjC object type:
389+ NSData *data = [NSData dataWithBytes: (attribute + 3 ) length: strlen (attribute) - 4 ];
390+ NSString *className = [[NSString alloc ] initWithData: data encoding: NSUTF8StringEncoding];
391+ return className;
392+ }
393+ }
394+ return @" " ;
370395}
371396
372-
397+ /*
373398static const char * getPropertyType(objc_property_t property) {
374399 const char *attributes = property_getAttributes(property);
375400 char buffer[1 + strlen(attributes)];
@@ -382,7 +407,7 @@ -(NSString *)classOfPropertyNamed:(NSString *)propName {
382407 if you want a list of what will be returned for these primitives, search online for
383408 "objective-c" "Property Attribute Description Examples"
384409 apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc.
385- */
410+
386411 return (const char *)[[NSData dataWithBytes:(attribute + 1) length:strlen(attribute) - 1] bytes];
387412 }
388413 else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) {
@@ -391,11 +416,13 @@ -(NSString *)classOfPropertyNamed:(NSString *)propName {
391416 }
392417 else if (attribute[0] == 'T' && attribute[1] == '@') {
393418 // it's another ObjC object type:
419+ NSData *data = [NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4];
420+ NSString *asdf = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
394421 return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes];
395422 }
396423 }
397424 return "";
398- }
425+ }*/
399426
400427+(NSArray *)arrayFromJSON : (NSArray *)jsonArray ofObjects : (NSString *)obj {
401428 // NSString *filteredObject = [NSString stringWithFormat:@"%@s",obj];
0 commit comments