#import <Foundation/Foundation.h> @implementation nsdictionary (Log)-(NSString *) Descriptionwithlocale: (ID) locale{nsmutablestring *str = [nsmutablestring string]; [str appendstring:@ "{\ n"]; Traverse the dictionary for all key-value pairs [self enumeratekeysandobjectsusingblock:^ (ID key, id obj, BOOL *stop) {[str appendformat:@ "\t%@ = %@,\n ", key, obj]; }]; [Str appendstring:@ "}"]; Find out the last, range nsrange range = [str rangeofstring:@], "Options:nsbackwardssearch"; if (range.length! = 0) {//Remove the last one, [str deletecharactersinrange:range]; } return str;} @end @implementation Nsarray (Log)-(NSString *) Descriptionwithlocale: (ID) locale{nsmutablestring *str = [NSMutableStri ng string]; [str appendstring:@ "[\ n"]; Iterates through all elements of an array [self enumerateobjectsusingblock:^ (id obj, Nsuinteger idx, BOOL *stop) {[str appendformat:@ '%@,\n ' , obj]; }]; [Str appendstring:@ "]"]; Find out the last, range nsrange range = [str rangeofstring:@ "," Options:nsbackwardssearch "; if (range.length! = 0) {//Remove the last one, [str deletecharactersinrange:range]; } return str;} @end
iOS nslog print dictionary for Chinese