/
NSDictionary+XPCParse.m
41 lines (36 loc) · 1.29 KB
/
NSDictionary+XPCParse.m
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// NSDictionary+XPCParse.m
// XPCKit
//
// Created by Steve Streza on 7/25/11.
// Copyright 2011 Mustacheware. All rights reserved.
//
#import "NSDictionary+XPCParse.h"
#import "NSObject+XPCParse.h"
@implementation NSDictionary (XPCParse)
+(NSDictionary *)dictionaryWithContentsOfXPCObject:(xpc_object_t)object{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
xpc_dictionary_apply(object, ^bool(const char *key, xpc_object_t value){
NSString *nsKey = [NSString stringWithCString:key encoding:NSUTF8StringEncoding];
id nsValue = [NSObject objectWithXPCObject:value];
if(nsKey && nsValue){
[dict setObject:nsValue forKey:nsKey];
}
return true;
});
return [[dict copy] autorelease];
}
-(xpc_object_t)newXPCObject{
xpc_object_t dictionary = xpc_dictionary_create(NULL, NULL, 0);
for(NSString *key in [self allKeys]){
id value = [self objectForKey:key];
if([value respondsToSelector:@selector(newXPCObject)]){
xpc_object_t xpcValue = [value newXPCObject];
xpc_dictionary_set_value(dictionary, [key cStringUsingEncoding:NSUTF8StringEncoding], xpcValue);
// }else{
// NSLog(@"Error parsing %@: Cannot handle %@ data", key, [value class]);
}
}
return dictionary;
}
@end