description 数组的中文打印

打印一个对象:NSLog(@"%@", stu); 默认情况下打印的时对象的名字和内存地址;这时需要重写description方法

// 重写description方法
- (NSString *)description
{
    return [NSString stringWithFormat:@"title:%@,icon:%@,answer:%@,options:%@", self.title, self.icon, self.answer, self.options ];
}
// 其中最后一个options是一个数组,其他的可以正常打印,只有数组不能打印中,这时需要给NSArray扩充一个类,重写:descriptionWithLocale方法

在NSArray的分类 NSArray + log中重写方法:descriptionWithLocale

- (NSString *)descriptionWithLocale:(id)locale
{
    NSMutableString *strM = [NSMutableString string];
    [strM appendString:@"(
"];
    
    for (id obj in self) {
        [strM appendFormat:@"	%@,
", obj];
    }
    [strM appendString:@")"];

    return strM;
}

这样可以打印中文了,一般是在从plist文件中读取到了一些属性,其中的某个属性是数组,编程时要看看数组是否取到了,就可以通过上述的打印办法;

原文地址:https://www.cnblogs.com/cxbblog/p/3763268.html