Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 3.99 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Error while getting properties types of large class in objective-C
  2. -(NSDictionary*) getPropertiesOfClass:(Class) clazz
  3. {
  4.     NSMutableDictionary* dict = [NSMutableDictionary dictionary];
  5.     unsigned int outCount, i;
  6.     objc_property_t *properties = class_copyPropertyList(clazz, &outCount);
  7.     for(i = 0; i < outCount; i++)
  8.     {
  9.         objc_property_t _property = properties[i];
  10.         const char *propName = property_getName(_property);
  11.         if(propName)
  12.         {
  13.             const char *propType = getPropertyType(_property);
  14.             NSString *propertyName = [NSString stringWithCString:propName encoding:NSUTF8StringEncoding];
  15.             NSString *propertyType = [NSString stringWithCString:propType encoding:NSUTF8StringEncoding];
  16.             [dict setValue:propertyType forKey:propertyName];
  17.         }
  18.     }
  19.     free(properties);
  20.     return dict;
  21. }
  22.  
  23. static const char *getPropertyType(objc_property_t property)
  24. {
  25.     const char *attributes = property_getAttributes(property);
  26.     char buffer[1 + strlen(attributes)];
  27.     strcpy(buffer, attributes);
  28.     char *state = buffer, *attribute;
  29.     while ((attribute = strsep(&state, ",")) != NULL)
  30.     {
  31.         if (attribute[0] == 'T')
  32.         {
  33.             return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes];
  34.         }
  35.     }
  36.     return "@";
  37. }
  38.        
  39. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:]: absurd length: 4294967294, maximum size: 2147483648 bytes'
  40. *** Call stack at first throw:
  41. (
  42.     0   CoreFoundation                      0x0101e5a9 __exceptionPreprocess + 185
  43.     1   libobjc.A.dylib                     0x01172313 objc_exception_throw + 44
  44.     2   CoreFoundation                      0x00fd6ef8 +[NSException raise:format:arguments:] + 136
  45.     3   CoreFoundation                      0x00fd6e6a +[NSException raise:format:] + 58
  46.     4   Foundation                          0x00800b6b -[NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:] + 135
  47.     5   Foundation                          0x00811801 -[NSData(NSData) initWithBytes:length:] + 72
  48.     6   solit                               0x00033449 -[ObjectMapper(private) getPropertiesOfClass:] + 489
  49.     7   solit                               0x00031fa5 -[ObjectMapper objectFromDictionary:object:] + 197
  50.     8   solit                               0x000327b3 -[ObjectMapper objectFromDictionary:object:] + 2259
  51.     9   solit                               0x00033913 -[NSDictionary(ObjectMapper) toObject:withTypes:] + 243
  52.     10  solit                               0x00031474 -[JsonWSCaller call:types:error:] + 196
  53.     11  solit                               0x0003f4c2 +[SummaryWSCaller getFastData:] + 354
  54.     12  solit                               0x00006fd9 -[PartSearchResultView tableView:didSelectRowAtIndexPath:] + 233
  55.     13  UIKit                               0x00110b68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
  56.     14  UIKit                               0x00106b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
  57.     15  Foundation                          0x0082079e __NSFireDelayedPerform + 441
  58.     16  CoreFoundation                      0x00fff8c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
  59.     17  CoreFoundation                      0x01000e74 __CFRunLoopDoTimer + 1220
  60.     18  CoreFoundation                      0x00f5d2c9 __CFRunLoopRun + 1817
  61.     19  CoreFoundation                      0x00f5c840 CFRunLoopRunSpecific + 208
  62.     20  CoreFoundation                      0x00f5c761 CFRunLoopRunInMode + 97
  63.     21  GraphicsServices                    0x012561c4 GSEventRunModal + 217
  64.     22  GraphicsServices                    0x01256289 GSEventRun + 115
  65.     23  UIKit                               0x000a7c93 UIApplicationMain + 1160
  66.     24  solit                               0x00002289 main + 121
  67.     25  solit                               0x00002205 start + 53
  68. )