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

  • 相关阅读:
    oracle改表语句
    pr视频过渡效果
    远程桌面连接
    kill-power
    Leetcode 466.统计重复个数
    Leetcode 464.我能赢吗
    Leetcode 462.最少移动次数使数组元素相等
    Leetcode 459.重复的子字符串
    Leetcode 458.可怜的小猪
    Leetcode 457.环形数组循环
  • 原文地址:https://www.cnblogs.com/cxbblog/p/3763268.html
Copyright © 2011-2022 走看看