-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNSArray+NullReplacement.m
More file actions
28 lines (23 loc) · 1017 Bytes
/
NSArray+NullReplacement.m
File metadata and controls
28 lines (23 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// NSArray+NullReplacement.m
// ADAM - Ausbau der Digitalisierung im Anlagenmanagement
//
// Created by Jonathan Lucas Fritz on 16.08.16.
// Copyright © 2016 NOSCIO. All rights reserved.
//
#import "NSArray+NullReplacement.h"
#import "NSDictionary+NullReplacement.h"
@implementation NSArray (NullReplacement)
- (NSArray *)arrayByReplacingNullsWithBlanks {
NSMutableArray *replaced = [self mutableCopy];
const id nul = [NSNull null];
const NSString *blank = @"";
for (int idx = 0; idx < [replaced count]; idx++) {
id object = [replaced objectAtIndex:idx];
if (object == nul) [replaced replaceObjectAtIndex:idx withObject:blank];
else if ([object isKindOfClass:[NSDictionary class]]) [replaced replaceObjectAtIndex:idx withObject:[object dictionaryByReplacingNullsWithBlanks]];
else if ([object isKindOfClass:[NSArray class]]) [replaced replaceObjectAtIndex:idx withObject:[object arrayByReplacingNullsWithBlanks]];
}
return [replaced copy];
}
@end