MapsIndoors iOS SDK
V3
|
#import <MPJSONModel.h>
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: |
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.
+ (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:
array | list of MPJSONModel objects |
MPJSONModelTypeNotAllowedException | thrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories |
+ (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.
array | list of dictionaries to be imported as models |
MPJSONModelTypeNotAllowedException | thrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories |
MPJSONModelInvalidDataException | thrown when the input data does not include all required keys |
- (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.
string | JSON text data |
err | an initialization error or nil |
MPJSONModelTypeNotAllowedException | thrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories |
- (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.
string | JSON text data |
encoding | the text encoding to use when parsing the string (see NSStringEncoding) |
err | an initialization error or nil |
MPJSONModelTypeNotAllowedException | thrown when unsupported type is found in the incoming JSON, or a property type in your model is not supported by MPJSONValueTransformer and its categories |
+ (MPJSONKeyMapper *) keyMapper |
Overwrite in your models if your property names don't match your JSON key names. Lookup MPJSONKeyMapper docs for more details.
- (BOOL) mergeFromDictionary: | (NSDictionary *) | dict | |
useKeyMapping: | (BOOL) | useKeyMapping | |
error: | (NSError **) | error | |
Merges values from the given dictionary into the model instance.
dict | dictionary with values |
useKeyMapping | if 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 |
+ (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.
propertyName | the name of the property |
+ (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.
propertyName | the name of the property |
- (NSData *) toJSONData |
Export the whole object to a JSON data text string
- (NSData *) toJSONDataWithKeys: | (NSArray< NSString * > *) | propertyNames |
Export the specified properties of the object to a JSON data text string
propertyNames | the properties to export; if nil, all properties exported |
- (NSString *) toJSONString |
Export the whole object to a JSON data text string
- (NSString *) toJSONStringWithKeys: | (NSArray< NSString * > *) | propertyNames |
Export the specified properties of the object to a JSON data text string
propertyNames | the properties to export; if nil, all properties exported |
- (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.
error | a pointer to an NSError object, to pass back an error if needed |