Created
May 11, 2011 22:16
-
-
Save darkseed/967514 to your computer and use it in GitHub Desktop.
Output properties of an object
This file contains 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
- ( 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