#import//导入runtime头文件
@implementationCommentModel
- (NSString*)description {
//初始化一个字典
NSMutableDictionary*dictionary = [NSMutableDictionarydictionary];
//得到当前class的所有属性
uintcount;
objc_property_t*properties =class_copyPropertyList([selfclass], &count);
//循环并用KVC得到每个属性的值
for(inti =0; i
objc_property_tproperty = properties[i];
NSString*name =@(property_getName(property));
idvalue = [selfvalueForKey:name]?:@"nil";//默认值为nil字符串
[dictionarysetObject:valueforKey:name];//装载到字典里
}
//释放
free(properties);
//return
return[NSStringstringWithFormat:@"<%@: %p> -- %@",[selfclass],self,dictionary];
}