MapsIndoors iOS SDK  V3
List of all members
MPJSONKeyMapper Class Reference

#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:
 

Detailed Description

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];
}

Method Documentation

◆ baseMapper:withModelToJSONExceptions:

+ (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.

◆ convertValue:

- (NSString *) convertValue: (NSString *)  value

Combined converter method

Parameters
valuethe source name
Returns
MPJSONKeyMapper instance

◆ initWithModelToJSONBlock:

- (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.

Parameters
toJSONtransforms your model property name to a JSON key

◆ initWithModelToJSONDictionary:

- (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.

Parameters
toJSONmap dictionary, in the format:
"myCamelCaseName":@"crazy_JSON_name"}
Returns
MPJSONKeyMapper instance

◆ mapperForSnakeCase

+ (instancetype) mapperForSnakeCase

Given a camelCase model property, this mapper finds JSON keys using the snake_case equivalent.

◆ mapperForTitleCase

+ (instancetype) mapperForTitleCase

Given a camelCase model property, this mapper finds JSON keys using the TitleCase equivalent.

Property Documentation

◆ modelToJSONKeyBlock

- (MPJSONModelKeyMapBlock) modelToJSONKeyBlock
readnonatomicassign

Block, which takes in a property name and converts it to the corresponding JSON key name


The documentation for this class was generated from the following file: