Created
October 30, 2015 03:02
-
-
Save jayrhynas/0561805f331d6ead5070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSDictionary (Unicode) | |
- (NSString *)unicodeDescription; | |
- (NSString *)unicodeDescription:(int)level; | |
@end | |
@interface NSArray (Unicode) | |
- (NSString *)unicodeDescription; | |
- (NSString *)unicodeDescription:(int)level; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSDictionary (Unicode) | |
- (NSString *)unicodeDescription { | |
return [self unicodeDescription:0]; | |
} | |
- (NSString *)unicodeDescription:(int)level { | |
NSMutableString *prefix = [[NSMutableString alloc] init]; | |
for (int i = 0; i < level; i++) { | |
[prefix appendString:@" "]; | |
} | |
NSMutableString *str = [[NSMutableString alloc] init]; | |
[str appendFormat:@"%@{\n", prefix]; | |
for (id key in self) { | |
[str appendFormat:@"%@ %@ = ", prefix, key]; | |
id val = self[key]; | |
NSString *valStr; | |
if ([val isKindOfClass:[NSDictionary class]]) { | |
valStr = [(NSDictionary *)val unicodeDescription:level + 1]; | |
} else if ([val isKindOfClass:[NSArray class]]) { | |
valStr = [(NSArray *)val unicodeDescription:level + 1]; | |
} else { | |
valStr = [val description]; | |
} | |
[str appendFormat:@"%@;\n", valStr]; | |
} | |
[str appendFormat:@"%@}", prefix]; | |
return str; | |
} | |
@end | |
@implementation NSArray (Unicode) | |
- (NSString *)unicodeDescription { | |
return [self unicodeDescription:0]; | |
} | |
- (NSString *)unicodeDescription:(int)level { | |
NSMutableString *prefix = [[NSMutableString alloc] init]; | |
for (int i = 0; i < level; i++) { | |
[prefix appendString:@" "]; | |
} | |
NSMutableString *str = [[NSMutableString alloc] init]; | |
[str appendFormat:@"%@(\n", prefix]; | |
for (id val in self) { | |
[str appendFormat:@"%@ ", prefix]; | |
NSString *valStr; | |
if ([val isKindOfClass:[NSDictionary class]]) { | |
valStr = [(NSDictionary *)val unicodeDescription:level + 1]; | |
} else if ([val isKindOfClass:[NSArray class]]) { | |
valStr = [(NSArray *)val unicodeDescription:level + 1]; | |
} else { | |
valStr = [val description]; | |
} | |
[str appendFormat:@"%@,\n", valStr]; | |
} | |
[str appendFormat:@"%@)", prefix]; | |
return str; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Collections+Unicode.h" | |
NSLog(@"%@", [@{@"céréales": @"hi", @"test": @[@1, @"1"]} unicodeDescription]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment