Skip to content

Instantly share code, notes, and snippets.

@rbsgn
Created February 22, 2011 20:42
Show Gist options
  • Save rbsgn/839349 to your computer and use it in GitHub Desktop.
Save rbsgn/839349 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface NSObject (YXDebug)
- (NSString *)yx_description;
@end
#import "NSObject-Verbose.h"
#import <objc/runtime.h>
@implementation NSObject (YXDebug)
- (NSString *)yx_description {
unsigned int count = 0;
objc_property_t * properties = class_copyPropertyList([self class], &count);
NSMutableString * result = [[NSMutableString alloc] init];
[result appendFormat:@"<%@: %p> {\n", NSStringFromClass([self class]), self];
for (unsigned int i = 0; i < count; i++) {
NSString * name = [NSString stringWithUTF8String:property_getName(properties[i])];
id value = [self valueForKey:name];
[result appendFormat:@"%@ - %@,\n", name, [value description]];
}
[result appendString:@"}\n"];
if (properties != NULL) {
free(properties);
}
return [result autorelease];
}
@end
@unixpickle
Copy link

u need to free properties!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment