On Feb 5, 2015, at 3:54 PM, Seth Willits <sli...@araelium.com> wrote:
>> How would you think about implementing this? It seems like I run into this >> need year after year after year. > > > NSString * NSObjectDescriptionUsingProperties(id obj) > { > unsigned int propCount; > objc_property_t * propList = class_copyPropertyList([obj class], > &propCount); > NSMutableString * ms = [NSMutableString stringWithFormat:@"<%@: %p>", > NSStringFromClass([obj class]), obj]; > if (propCount > 0) { > [ms appendString:@" {\n"]; > for (unsigned int i = 0; i < propCount; i++) { > const char * propName = property_getName(propList[i]); > [ms appendFormat:@"\t%s = %@,\n", propName, [obj > valueForKey:[NSString stringWithUTF8String:propName]]]; > } > [ms appendString:@"}"]; > free(propList); > } > > return ms; > } > And if you want to get really creative, you could swizzle NSObject's -description to call it. -- Seth Willits _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com