OC编码问题输出中文
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSMutableArray *arr=[NSMutableArray arrayWithObjects:@"中文",@"英文",@"编码", nil];
NSLog(@"%@",arr);
NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithObjectsAndKeys:@"中文",@"one",@"编码",@"two",nil];
NSLog(@"%@",dic);
NSMutableSet *set=[NSMutableSet setWithObjects:@"中文",@"英文",@"编码", nil];
NSLog(@"%@",set);
}
return 0;
}
出现编码问题,不能正常显示中文
2016-07-21 22:19:48.117 测试[1618:495781] (
"\U4e2d\U6587",
"\U82f1\U6587",
"\U7f16\U7801"
)
2016-07-21 22:19:48.117 测试[1618:495781] {
one = "\U4e2d\U6587";
two = "\U7f16\U7801";
}
2016-07-21 22:19:48.118 测试[1618:495781] {(
"\U7f16\U7801",
"\U82f1\U6587",
"\U4e2d\U6587"
)}
Program ended with exit code: 0
为数组添加类别
#import "NSArray+ToChinese.h" //类别名称
@implementation NSArray (ToChinese)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *string=[[NSMutableString alloc]init];
[string appendString:@"("];
for (id obj in self) { //self就是当前可变数组,遍历数组中的对象拼接成新的字符串返回
[string appendFormat:@"\n\t%@",obj];
}
[string appendString:@"\n)"];
return string;
}
@end
为字典添加类别
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *string=[[NSMutableString alloc]init ];
[string appendString:@"{"];
NSString* value=[NSString string];
for (id obj in self) { //self就是当前可变字典,遍历字典中的对象拼接成新的字符串返回
value=[self objectForKey:obj];
[string appendFormat:@"\n\t%@ = %@",obj,value];
}
[string appendString:@"\n}"];
return string;
}
为集合添加类别
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *str=[[NSMutableString alloc]init];
[str appendString:@"("];
for(id obj in self) { //self就是当前可变集合,遍历集合中的对象拼接成新的字符串返回
[str appendFormat:@"\n\t%@",obj];
}
[str appendString:@"\n)"];
return str;
}
正常显示中文
2016-07-21 22:18:58.727 编码问题[1572:488898] (
中文
英文
编码
)
2016-07-21 22:18:58.728 编码问题[1572:488898] {
one = 中文
two = 编码
}
2016-07-21 22:18:58.728 编码问题[1572:488898] (
编码
英文
中文
)
Program ended with exit code: 0