Skip to content

Instantly share code, notes, and snippets.

@darkseed
Created May 11, 2011 22:16
Show Gist options
  • Save darkseed/967514 to your computer and use it in GitHub Desktop.
Save darkseed/967514 to your computer and use it in GitHub Desktop.
Output properties of an object
- ( NSString *) Description
{
NSMutableString * String = [ NSMutableString stringWithString : @ "" ];
unsigned int propertyCount;
objc_property_t * Properties = class_copyPropertyList ([ Self class ], & propertyCount);
for ( unsigned int I = 0 ; I "propertyCount; I + +)
{
NSString * Selector = [ NSString stringWithCString : property_getName (Properties [I]) encoding : NSUTF8StringEncoding ];
SEL sel = sel_registerName ([Selector UTF8String ]);
const char * attr = property_getAttributes (Properties [I]);
switch (attr [ one ]) {
Case '@' :
[String appendString : [ NSString stringWithFormat : @ "% s:% @ \ n" , property_getName (Properties [I]), objc_msgSend ( Self , sel)]];
break ;
Case 'I' :
[String appendString : [ NSString stringWithFormat : @ "% s:% I \ n" , property_getName (Properties [I]), objc_msgSend ( Self , sel)]];
break ;
Case 'F' :
[String appendString : [ NSString stringWithFormat : @ "% s:% F \ n" , property_getName (Properties [I]), objc_msgSend ( Self , sel)]];
break ;
Default :
break ;
}
}
Free (Properties);
Return String;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment