blob: 5745955aef86f2a1dfff0564cb73d1af8b3a0fce (
plain)
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
42
43
44
45
46
|
//
// NSDictionary+MCO.m
// mailcore2
//
// Created by DINH Viêt Hoà on 1/29/13.
// Copyright (c) 2013 MailCore. All rights reserved.
//
#import "NSDictionary+MCO.h"
#include "MCBaseTypes.h"
#import "NSObject+MCO.h"
@implementation NSDictionary (MCO)
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
return [self mco_dictionaryWithMCHashMap:(mailcore::HashMap *) object];
}
+ (NSDictionary *) mco_dictionaryWithMCHashMap:(mailcore::HashMap *)hashmap
{
NSMutableDictionary * result = [NSMutableDictionary dictionary];
mailcore::Array * keys = hashmap->allKeys();
for(unsigned int i = 0 ; i < keys->count() ; i ++) {
mailcore::Object * mcKey = keys->objectAtIndex(i);
mailcore::Object * mcValue = hashmap->objectForKey(mcKey);
id key = [NSObject mco_objectWithMCObject:mcKey];
id value = [NSObject mco_objectWithMCObject:mcValue];
[result setObject:value forKey:key];
}
return result;
}
- (mailcore::HashMap *) mco_mcHashMap
{
mailcore::HashMap * result = mailcore::HashMap::hashMap();
for(NSObject * key in self) {
NSObject * value = [self objectForKey:key];
result->setObjectForKey([key mco_mcObject], [value mco_mcObject]);
}
return result;
}
@end
|