Skip to content

Instantly share code, notes, and snippets.

@gustafnilklint
Created September 15, 2014 21:23
Show Gist options
  • Save gustafnilklint/2e005ff9f6001147c78d to your computer and use it in GitHub Desktop.
Save gustafnilklint/2e005ff9f6001147c78d to your computer and use it in GitHub Desktop.
NSDictionary print itself as litheral
//
// NSDictionary+prettyPrint.m
// GarageRemote
//
// Created by Gustaf Nilklint on 2014-09-15.
// Copyright (c) 2014 Gustaf Nilklint. All rights reserved.
//
#import "NSDictionary+prettyPrint.h"
@implementation NSDictionary (prettyPrint)
- (NSString*)myDescription;
{
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
options:NSJSONWritingPrettyPrinted
error:&error];
if (error) NSLog(@"Error: %@", error);
NSString *jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
NSString *litheralsString = [jsonString stringByReplacingOccurrencesOfString:@"{" withString:@"@{"];
litheralsString = [litheralsString stringByReplacingOccurrencesOfString:@"[" withString:@"@["];
litheralsString = [litheralsString stringByReplacingOccurrencesOfString:@" \"" withString:@"@\""];
return litheralsString;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment