打印一个对象: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:@"(\n"];
    
    for (id obj in self) {
        [strM appendFormat:@"\t%@,\n", obj];
    }
    [strM appendString:@")"];

    return strM;
}

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

相关文章:

  • 2021-05-31
  • 2021-06-04
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案