forked from RestKit/RestKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRKObjectMappable.m
More file actions
37 lines (31 loc) · 1.54 KB
/
Copy pathRKObjectMappable.m
File metadata and controls
37 lines (31 loc) · 1.54 KB
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
//
// RKObjectMappable.m
// RestKit
//
// Created by Blake Watters on 1/20/11.
// Copyright 2011 Two Toasters. All rights reserved.
//
#import "RKObjectMappable.h"
// Return all the mapped properties of object in a dictionary
NSDictionary* RKObjectMappableGetProperties(NSObject<RKObjectMappable>*object) {
NSDictionary* mappings = [[object class] elementToPropertyMappings];
NSMutableDictionary* propertyNamesAndValues = [NSMutableDictionary dictionaryWithCapacity:[mappings count]];
// Return all the properties of this model in a dictionary under their element names
for (NSString* elementName in mappings) {
NSString* propertyName = [mappings valueForKey:elementName];
id propertyValue = [object valueForKey:propertyName];
[propertyNamesAndValues setValue:propertyValue forKey:propertyName];
}
return [NSDictionary dictionaryWithDictionary:propertyNamesAndValues];
}
// Return all the mapped properties of object in a dictionary under their element names
NSDictionary* RKObjectMappableGetPropertiesByElement(NSObject<RKObjectMappable>*object) {
NSDictionary* mappings = [[object class] elementToPropertyMappings];
NSMutableDictionary* elementsAndPropertyValues = [NSMutableDictionary dictionaryWithCapacity:[mappings count]];
for (NSString* elementName in mappings) {
NSString* propertyName = [mappings valueForKey:elementName];
id propertyValue = [object valueForKey:propertyName];
[elementsAndPropertyValues setValue:propertyValue forKey:elementName];
}
return [NSDictionary dictionaryWithDictionary:elementsAndPropertyValues];
}