1 重写 - (NSString *)description{} 方法 打印完整日志
2 重写 - (NSString *)debugDescription{} 方法控制台打印
- (NSString *)description{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
uint count;
objc_property_t *properties = class_copyPropertyList([self class], &count);
for (int i = 0 ; i < count; i++) {
objc_property_t property = properties[i];
NSString *name = @(property_getName(property));
id value = [self valueForKey:name]?:@"nil";
[dict setObject:value forKey:name];
}
free(properties);
return [NSString stringWithFormat:@"<%@:%p>%@",[self class],self,dict];
}
- (NSString *)debugDescription{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
uint count;
objc_property_t *properties = class_copyPropertyList([self class], &count);
for (int i = 0 ; i < count; i++) {
objc_property_t property = properties[i];
NSString *name = @(property_getName(property));
id value = [self valueForKey:name]?:@"nil";
[dict setObject:value forKey:name];
}
free(properties);
return [NSString stringWithFormat:@"<%@:%p>%@",[self class],self,dict];
}
参考文章:http://www.jianshu.com/p/c173d1460463
网友评论