由于 Xcode 8 更新后,第三方插件基本上不能使用。
控制台输出的数据是Unicode格式,为了方便使用,只需要在项目中新建一个 .m 文件 Foundation+Log.m
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@implementation UIView (Log)
+ (NSString *)searchAllSubviews:(UIView *)superview {
NSMutableString *xml = [NSMutableString string];
NSString *class = NSStringFromClass(superview.class);
class = [class stringByReplacingOccurrencesOfString:@"_" withString:@""];
[xml appendFormat:@"<%@ frame=\"%@\">\n", class, NSStringFromCGRect(superview.frame)];
for (UIView *childView in superview.subviews) {
NSString *subviewXml = [self searchAllSubviews:childView];
[xml appendString:subviewXml];
}
[xml appendFormat:@"</%@>\n", class];
return xml;
}
- (NSString *)description
{
return [UIView searchAllSubviews:self];
}
@end
#pragma mark - 让网络请求回来的中文被unicode编码的数据汉字显示
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale {
NSMutableString *str = [NSMutableString string];
// 开头有个{
[str appendString:@"{\n"];
// 遍历字典的所有键值对
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[str appendFormat:@"\t%@ = %@,\n", key, obj];
}];
// 结尾有个}
[str appendString:@"}"];
// 查出最后一个,的范围
NSRange range = [str rangeOfString:@"," options:NSBackwardsSearch];
if (range.length) {
// 删掉最后一个,
[str deleteCharactersInRange:range];
}
return str;
}
@end
@implementation NSArray (Log)
- (NSString *)descriptionWithLocale:(id)locale {
NSMutableString *str = [NSMutableString string];
// 开头有个[
[str appendString:@"[\n"];
// 遍历数组的所有元素
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[str appendFormat:@"%@,\n", obj];
}];
// 结尾有个]
[str appendString:@"]"];
// 查出最后一个,的范围
NSRange range = [str rangeOfString:@"," options:NSBackwardsSearch];
if (range.length) {
// 删掉最后一个,
[str deleteCharactersInRange:range];
}
return str;
}
@end
将这段代码放入 Foundation+Log 中就可以实现控制台输出中文而不是Unicode