Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PList compliancy

  • Loading branch information...
commit d9603eec2a8395bec647a9d6205b63d091d9046b 1 parent e3d9b39
@mxcl authored
Showing with 44 additions and 0 deletions.
  1. +8 −0 NSObject+mxcl.h
  2. +36 −0 NSObject+mxcl.m
View
8 NSObject+mxcl.h
@@ -8,3 +8,11 @@
+ (id)objectWithJSONString:(NSString *)json;
@end
+
+
+@interface NSObject (PListCompliant)
+
+// removes [NSNull null] from NSArrays and NSDictionaries
+- (id)plistCompliantObject;
+
+@end
View
36 NSObject+mxcl.m
@@ -1,6 +1,7 @@
#import "NSObject+mxcl.h"
#import <objc/runtime.h>
+
@implementation NSObject (mxcl)
- (void)dumpSelectors {
@@ -20,3 +21,38 @@ + (id)objectWithJSONString:(NSString *)json {
}
@end
+
+
+
+@implementation NSDictionary (PListCompliant)
+
+- (NSDictionary *)plistCompliantObject {
+ NSMutableDictionary *dict = @{}.mutableCopy;
+ [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
+ if ([obj respondsToSelector:@selector(plistCompliantObject)]) {
+ dict[key] = [obj plistCompliantObject];
+ } else if (obj != [NSNull null]) {
+ dict[key] = obj;
+ }
+ }];
+ return dict;
+}
+
+@end
+
+
+
+@implementation NSArray (PListCompliant)
+
+- (id)plistCompliantObject {
+ NSMutableArray *array = @[].mutableCopy;
+ for (id obj in self) {
+ if ([obj respondsToSelector:@selector(plistCompliantObject)])
+ [array addObject:[obj plistCompliantObject]];
+ else if (obj != [NSNull null])
+ [array addObject:array];
+ }
+ return array;
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.