How to get a dictionary of NSObject attribute names and values
During recent development with SBJSON, it was discovered that SBJSON could not support custom objects, and two implementation scenarios were considered. A way to implement a custom object's Category at layer one of the SBJSON framework to support proxyForJson. Another option is for the application layer to convert custom objects into dictionaries of attribute names and attribute values, which are then processed by SBJSON. Since SBJSON is maintained by an underlying library, the compromise is to handle custom objects at the application level. After some investigation and searching, we found the following implementation methods:
#import #import @interface NSObject (PropertyListing)// aps suffix to avoid namespace collsion// ... for Andrew Paul Sardone- (NSDictionary *)properties_aps;@end@implementation NSObject (PropertyListing)- (NSDictionary *)properties_aps {NSMutableDictionary *props = [NSMutableDictionary dictionary];unsigned int outCount, i;objc_property_t *properties = class_copyPropertyList([self class], &outCount);for (i = 0; i