# Import <objc/runtime. h>
@ Implementation nsobject (propertylisting)
/* Obtain all attributes of an object */
-(Nsdictionary *) properties_aps
{
Nsmutabledictionary * props = [nsmutabledictionarydictionary];
Unsigned int outcount, I;
Objc_property_t * properties = class_copypropertylist ([self class], & outcount );
For (I = 0; I <outcount; I ++)
{
Objc_property_t property = properties [I];
Const char * char_f = property_getname (property );
Nsstring * propertyname = [nsstringstringwithuf8string: char_f];
Id propertyvalue = [selfvalueforkey :( nsstring *) propertyname];
If (propertyvalue) [props setobject: propertyvalue forkey: propertyname];
}
Free (properties );
Return props;
}
/* Get all methods of the object */
-(Void) printmothlist
{
Unsigned int mothcout_f = 0;
Method * mothlist_f = class_copymethodlist ([self class], & mothcout_f );
For (INT I = 0; I <mothcout_f; I ++)
{
Method temp_f = mothlist_f [I];
IMP imp_f = method_getimplementation (temp_f );
Sel name_f = method_getname (temp_f );
Const char * name_s = sel_getname (method_getname (temp_f ));
Int arguments = method_getnumberofarguments (temp_f );
Const char * encoding = method_gettypeencoding (temp_f );
Nslog (@ "method name: % @, number of parameters: % d, encoding method: % @", [nsstringstringwithuf8string: name_s],
Arguments,
[Nsstringstringwithuf8string: encoding]);
}
Free (mothlist_f );
}