Skip to content

Instantly share code, notes, and snippets.

@mralexgray
Last active September 3, 2019 09:02
Show Gist options
  • Save mralexgray/b51a60dac974b9f952a0 to your computer and use it in GitHub Desktop.
Save mralexgray/b51a60dac974b9f952a0 to your computer and use it in GitHub Desktop.
A concise category on NSObject to log all declared properties, pretty-like, using minimal SLOC.
#import <objc/message.h>
#define DECORATE printf("\n\n+*%%$%%*+-+*%%$%%*+-+*%%$-+*%%$%%*+-+*%%$%%*+-+*%%$-+*%%$%%*+-+*%%$%%*+-\n\n")
@implementation NSObject (logProperties) - (void) logProperties { DECORATE; @autoreleasepool { unsigned int propCt = 0;
const char * myName = [self.description substringWithRange:
(NSRange){1,[self.description rangeOfString:@":"].location-1}].UTF8String;
objc_property_t *pA = class_copyPropertyList(self.class, &propCt);
for (int i = 0; i < propCt; i++) { NSString *name; printf("%s [%s] = %s\n", myName,
(name = [NSString.alloc initWithUTF8String:property_getName(pA[i])]).UTF8String,
[objc_msgSend(self,NSSelectorFromString(name)) description].UTF8String);
} free(pA); } DECORATE; }
@end
+*%$%*+-+*%$%*+-+*%$-+*%$%*+-+*%$%*+-+*%$-+*%$%*+-+*%$%*+-
BLWebSocketsServer [running] = (null)
BLWebSocketsServer [port] = (null)
BLWebSocketsServer [protocolName] = (null)
BLWebSocketsServer [completionBlock] = (null)
BLWebSocketsServer [timer] = (null)
BLWebSocketsServer [networkQueue] = <OS_dispatch_queue: com.blwebsocketsserver.network[0x10010aa80]>
BLWebSocketsServer [context] = (null)
BLWebSocketsServer [asyncMessageQueue] = <BLAsyncMessageQueue: 0x100102370>
BLWebSocketsServer [handleRequestBlock] = <__NSGlobalBlock__: 0x100007300>
BLWebSocketsServer [sessionIdIncrementalCount] = (null)
+*%$%*+-+*%$%*+-+*%$-+*%$%*+-+*%$%*+-+*%$-+*%$%*+-+*%$%*+-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment