MapsIndoors iOS SDK  V3
List of all members
MPJSONModel Class Reference

#import <MPJSONModel.h>

Inheritance diagram for MPJSONModel:
<AbstractMPJSONModelProtocol> MPAppData MPBuilding MPBuildingDataset MPFloor MPGeometry MPLocation MPLocationDataset MPLocationDisplayRule MPMapStyle MPMessageDataset MPPositionResult MPRoute MPRouteBounds MPRouteCoordinate MPRouteLeg MPRouteProperty MPRouteResult MPRouteStep MPSolution MPTransitAgency MPTransitDetails MPTransitLine MPTransitStop MPTransitTime MPTransitVehicle MPType MPVenue MPVenueCollection

Instance Methods

Creating and initializing models
(instancetype) - initWithString:error:
 
(instancetype) - initWithString:usingEncoding:error:
 
Exporting model contents
(NSString *) - toJSONString
 
(NSData *) - toJSONData
 
(NSString *) - toJSONStringWithKeys:
 
(NSData *) - toJSONDataWithKeys:
 
Validation
(BOOL) - validate:
 
- Instance Methods inherited from <AbstractMPJSONModelProtocol>
(instancetype) - initWithDictionary:error:
 
(instancetype) - initWithData:error:
 
(NSDictionary *) - toDictionary
 
(NSDictionary *) - toDictionaryWithKeys:
 

Class Methods

Batch methods
(NSMutableArray *) + arrayOfModelsFromDictionaries:error:
 
(NSMutableArray *) + arrayOfModelsFromData:error:
 
(NSMutableArray *) + arrayOfModelsFromString:error:
 
(NSMutableDictionary *) + dictionaryOfModelsFromDictionary:error:
 
(NSMutableDictionary *) + dictionaryOfModelsFromData:error:
 
(NSMutableDictionary *) + dictionaryOfModelsFromString:error:
 
(NSMutableArray *) + arrayOfDictionariesFromModels:
 
(NSMutableDictionary *) + dictionaryOfDictionariesFromModels:
 

Key mapping

(MPJSONKeyMapper *) + keyMapper
 
(BOOL) + propertyIsOptional:
 
(BOOL) + propertyIsIgnored:
 
(Class) + classForCollectionProperty:
 
(BOOL) - mergeFromDictionary:useKeyMapping:error:
 

Detailed Description

The MPJSONModel is an abstract model class, you should not instantiate it directly, as it does not have any properties, and therefore cannot serve as a data model. Instead you should subclass it, and define the properties you want your data model to have as properties of your own class.

Method Documentation

◆ arrayOfDictionariesFromModels:

+ (NSMutableArray *) arrayOfDictionariesFromModels: (NSArray *)  array

If you have an NSArray of data model objects, this method takes it in and outputs a list of the matching dictionaries. This method does the opposite of arrayOfObjectsFromDictionaries:

Parameters
arraylist of MPJSONModel objects
Returns
a list of NSDictionary objects
Exceptions
MPJSONModelTypeNotAllowedExceptionthrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories
See also
arrayOfModelsFromDictionaries:

◆ arrayOfModelsFromDictionaries:error:

+ (NSMutableArray *) arrayOfModelsFromDictionaries: (NSArray *)  array
error: (NSError **)  err 

If you have a list of dictionaries in a JSON feed, you can use this method to create an NSArray of model objects. Handy when importing JSON data lists. This method will loop over the input list and initialize a data model for every dictionary in the list.

Parameters
arraylist of dictionaries to be imported as models
Returns
list of initialized data model objects
Exceptions
MPJSONModelTypeNotAllowedExceptionthrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories
MPJSONModelInvalidDataExceptionthrown when the input data does not include all required keys
See also
+ arrayOfDictionariesFromModels:

◆ initWithString:error:

- (instancetype) initWithString: (NSString *)  string
error: (MPJSONModelError **)  err 

Create a new model instance and initialize it with the JSON from a text parameter. The method assumes UTF8 encoded input text.

Parameters
stringJSON text data
erran initialization error or nil
Exceptions
MPJSONModelTypeNotAllowedExceptionthrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories
See also
- initWithString:usingEncoding:error: for use of custom text encodings

◆ initWithString:usingEncoding:error:

- (instancetype) initWithString: (NSString *)  string
usingEncoding: (NSStringEncoding)  encoding
error: (MPJSONModelError **)  err 

Create a new model instance and initialize it with the JSON from a text parameter using the given encoding.

Parameters
stringJSON text data
encodingthe text encoding to use when parsing the string (see NSStringEncoding)
erran initialization error or nil
Exceptions
MPJSONModelTypeNotAllowedExceptionthrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories

◆ keyMapper

+ (MPJSONKeyMapper *) keyMapper

Overwrite in your models if your property names don't match your JSON key names. Lookup MPJSONKeyMapper docs for more details.

◆ mergeFromDictionary:useKeyMapping:error:

- (BOOL) mergeFromDictionary: (NSDictionary *)  dict
useKeyMapping: (BOOL)  useKeyMapping
error: (NSError **)  error 

Merges values from the given dictionary into the model instance.

Parameters
dictdictionary with values
useKeyMappingif YES the method will use the model's key mapper and the global key mapper, if NO it'll just try to match the dictionary keys to the model's properties

◆ propertyIsIgnored:

+ (BOOL) propertyIsIgnored: (NSString *)  propertyName

Indicates whether the property with the given name is Ignored. To have a model with all of its properties being Ignored just return YES. This method returns by default NO, since the default behaviour is to have all properties required.

Parameters
propertyNamethe name of the property
Returns
a BOOL result indicating whether the property is ignored

◆ propertyIsOptional:

+ (BOOL) propertyIsOptional: (NSString *)  propertyName

Indicates whether the property with the given name is Optional. To have a model with all of its properties being Optional just return YES. This method returns by default NO, since the default behaviour is to have all properties required.

Parameters
propertyNamethe name of the property
Returns
a BOOL result indicating whether the property is optional

◆ toJSONData

- (NSData *) toJSONData

Export the whole object to a JSON data text string

Returns
JSON text data describing the data model

◆ toJSONDataWithKeys:

- (NSData *) toJSONDataWithKeys: (NSArray< NSString * > *)  propertyNames

Export the specified properties of the object to a JSON data text string

Parameters
propertyNamesthe properties to export; if nil, all properties exported
Returns
JSON text data describing the data model

◆ toJSONString

- (NSString *) toJSONString

Export the whole object to a JSON data text string

Returns
JSON text describing the data model

◆ toJSONStringWithKeys:

- (NSString *) toJSONStringWithKeys: (NSArray< NSString * > *)  propertyNames

Export the specified properties of the object to a JSON data text string

Parameters
propertyNamesthe properties to export; if nil, all properties exported
Returns
JSON text describing the data model

◆ validate:

- (BOOL) validate: (NSError **)  error

Overwrite the validate method in your own models if you need to perform some custom validation over the model data. This method gets called at the very end of the MPJSONModel initializer, thus the model is in the state that you would get it back when initialized. Check the values of any property that needs to be validated and if any invalid values are encountered return NO and set the error parameter to an NSError object. If the model is valid return YES.

NB: Only setting the error parameter is not enough to fail the validation, you also need to return a NO value.

Parameters
errora pointer to an NSError object, to pass back an error if needed
Returns
a BOOL result, showing whether the model data validates or not. You can use the convenience method [MPJSONModelError errorModelIsInvalid] to set the NSError param if the data fails your custom validation

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