Files
eqn.ios/Sources/Earthquake Network/Libs/Extensions/NSDictionary+EQNExtensions.m
T
2020-10-03 12:01:17 +02:00

37 lines
854 B
Objective-C

//
// NSDictionary+EQNExtensions.h
// Earthquake Network
//
// Created by Andrea Busi on 03/10/2020.
// Copyright © 2020 Earthquake Network. All rights reserved.
//
#import "NSDictionary+EQNExtensions.h"
@implementation NSDictionary (BVJSONString)
#pragma mark - Public
- (NSString *)eqn_jsonStringWithPrettyPrint:(BOOL)prettyPrint
{
NSError *error;
NSJSONWritingOptions options = prettyPrint ? NSJSONWritingPrettyPrinted : 0;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:options error:&error];
if (!jsonData) {
return @"{}";
}
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
- (id)eqn_safeObjectForKey:(id)aKey
{
NSObject *object = [self objectForKey:aKey];
if (object == [NSNull null]) {
return nil;
}
return object;
}
@end