Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to get a dictionary of NSObject attribute names and values

Shulou Source: shulou.com Published: 2022-06-03 07:51:57 11月23日 Update

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

Tags: Object scheme processing properties that is application layer method framework application support dictionary for this code underlying procedure link transmission development compromise search Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Shulou Tech Info Microsoft Redmi