Last active
December 19, 2015 21:18
-
-
Save mkuliszkiewicz/6019056 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSObject+LogProperties.h | |
| // | |
| // Gist created by Maciej Banasiewicz. | |
| // Log all properties of an object. | |
| // Credits: Tieme | |
| // Source: http://stackoverflow.com/questions/13922581/is-there-a-way-to-log-all-the-property-values-of-an-objective-c-instance | |
| #import <Foundation/Foundation.h> | |
| @interface NSObject (LogProperties) | |
| - (void)logProperties; | |
| - (NSString *)propertiesString; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSObject+LogProperties.h | |
| // | |
| // Gist created by Maciej Banasiewicz. | |
| // Log all properties of an object. | |
| // Credits: Tieme | |
| // Source: http://stackoverflow.com/questions/13922581/is-there-a-way-to-log-all-the-property-values-of-an-objective-c-instance | |
| #import "NSObject+LogProperties.h" | |
| #import <objc/runtime.h> | |
| @implementation NSObject (LogProperties) | |
| - (NSString *) propertiesString | |
| { | |
| NSMutableString *ret = [NSMutableString string]; | |
| [ret appendString:[NSString stringWithFormat:@"----------------------------------------------- Properties for object %@\n", [self class]]]; | |
| @autoreleasepool { | |
| unsigned int numberOfProperties = 0; | |
| objc_property_t *propertyArray = class_copyPropertyList([self class], &numberOfProperties); | |
| for (NSUInteger i = 0; i < numberOfProperties; i++) { | |
| objc_property_t property = propertyArray[i]; | |
| NSString *name = [[NSString alloc] initWithUTF8String:property_getName(property)]; | |
| [ret appendFormat:@"Property %@ Value: %@\n", name, [self valueForKey:name]]; | |
| } | |
| free(propertyArray); | |
| } | |
| [ret appendString:@"-----------------------------------------------\n"]; | |
| return ret; | |
| } | |
| - (void)logProperties | |
| { | |
| NSLog(@"%@", [self propertiesString]); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment