MapsIndoors iOS SDK
V3
|
#import <MPJSONKeyMapper.h>
Inherits NSObject.
Name converters | |
MPJSONModelKeyMapBlock | modelToJSONKeyBlock |
(NSString *) | - convertValue: |
Creating a key mapper | |
(instancetype) | - initWithModelToJSONBlock: |
(instancetype) | - initWithModelToJSONDictionary: |
(instancetype) | + mapperForSnakeCase |
(instancetype) | + mapperForTitleCase |
(instancetype) | + baseMapper:withModelToJSONExceptions: |
You won't need to create or store instances of this class yourself. If you want your model to have different property names than the JSON feed keys, look below on how to make your model use a key mapper.
For example if you consume JSON from twitter you get back underscore_case style key names. For example:
"profile_sidebar_border_color": "0094C2", "profile_background_tile": false,
To comply with Obj-C accepted camelCase property naming for your classes, you need to provide mapping between JSON keys and ObjC property names.
In your model overwrite the + (MPJSONKeyMapper *)keyMapper method and provide a MPJSONKeyMapper instance to convert the key names for your model.
If you need custom mapping it's as easy as:
+ (MPJSONKeyMapper *)keyMapper { return [[MPJSONKeyMapper alloc] initWithDictionary:"crazy_JSON_name":@"myCamelCaseName"}]; }
In case you want to handle underscore_case, use the predefined key mapper, like so:
+ (MPJSONKeyMapper *)keyMapper { return [MPJSONKeyMapper mapperFromUnderscoreCaseToCamelCase]; }
+ (instancetype) baseMapper: | (MPJSONKeyMapper *) | baseKeyMapper | |
withModelToJSONExceptions: | (NSDictionary *) | toJSON | |
Creates a MPJSONKeyMapper based on a built-in MPJSONKeyMapper, with specific exceptions. Use your MPJSONModel property names as keys, and the JSON key names as values.
- (NSString *) convertValue: | (NSString *) | value |
- (instancetype) initWithModelToJSONBlock: | (MPJSONModelKeyMapBlock) | toJSON |
Creates a MPJSONKeyMapper instance, based on the block you provide this initializer. The parameter takes in a MPJSONModelKeyMapBlock block:
NSString *(^MPJSONModelKeyMapBlock)(NSString *keyName)
The block takes in a string and returns the transformed (if at all) string.
toJSON | transforms your model property name to a JSON key |
- (instancetype) initWithModelToJSONDictionary: | (NSDictionary< NSString *, NSString * > *) | toJSON |
Creates a MPJSONKeyMapper instance, based on the mapping you provide. Use your MPJSONModel property names as keys, and the JSON key names as values.
toJSON | map dictionary, in the format: "myCamelCaseName":@"crazy_JSON_name"} |
+ (instancetype) mapperForSnakeCase |
Given a camelCase model property, this mapper finds JSON keys using the snake_case equivalent.
+ (instancetype) mapperForTitleCase |
Given a camelCase model property, this mapper finds JSON keys using the TitleCase equivalent.
|
readnonatomicassign |
Block, which takes in a property name and converts it to the corresponding JSON key name