笔记-数组与字典中文化实现打印

NSArray+Log

NSArray+Log.h

#import <Foundation/Foundation.h>

@interface NSArray (Log)

@end

NSArray+Log.m

#import "NSArray+Log.h"

@implementation NSArray (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
    NSMutableString *strM = [NSMutableString stringWithString:@"(\n"];
    for (id obj in self) {
        [strM appendFormat:@"\t%@,\n",obj];
    }
    [strM appendString:@")\n"];
    return strM;

}
@end

NSDictionary+Log.h

#import <Foundation/Foundation.h>

@interface NSDictionary (Log)

@end

NSDictionary+Log.m

#import "NSDictionary+Log.h"

@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
    NSMutableString *strM = [NSMutableString stringWithString:@"{\n"];
    for (id key in self.allKeys) {
        NSString *keyStr = [NSString stringWithFormat:@"\t%@ = ",key];
        id value = [self objectForKey:key];
        [strM appendString:keyStr];
        NSString *valueStr = [NSString stringWithFormat:@"%@;\n",value];
        [strM appendString:valueStr];
    }
    [strM appendString:@"}\n"];
    return strM;

}
@end

运用时,直接将此四项文件拖住项目文件

posted @ 2015-08-18 21:04  ios-C  阅读(153)  评论(0编辑  收藏  举报