zoukankan      html  css  js  c++  java
  • 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文件中读取到了一些属性,其中的某个属性是数组,编程时要看看数组是否取到了,就可以通过上述的打印办法;

  • 相关阅读:
    Python数据挖掘—回归—一元非线性回归
    Python数据挖掘—回归—线性回归
    Python 线程 进程 协程
    Python 异常处理
    Python Socket
    python mysql
    Python 面向对象
    Python 正则表达式
    Python 算法
    python 迭代器 生成器 装饰器
  • 原文地址:https://www.cnblogs.com/cxbblog/p/3763268.html
Copyright © 2011-2022 走看看