bilby91
bilby91

Reputation: 904

Restkit Mapping Dynamic key value

Im trying to map error responses from the server that are totally dynamic, like rails @model.errors.

My json reponse is like this:

{"errors":{"email":["has already been taken"],"password":["can't be blank"]}}

I have an error class in my ios App to model the errors.

@interface VVError : NSObject
@property (nonatomic,copy) NSString* key;
@property (nonatomic,copy) NSArray* messages;
@end

I couldn't find a way to map the response with my model class. Any help? Thanks

Upvotes: 0

Views: 170

Answers (1)

Wain
Wain

Reputation: 119031

Your error messages don't appear to be 'dynamic' from a format point of view. As such, the mapping is identical to a standard response. You have a good keypath (errors) to specify on the response descriptor. You also need to know and specify what HTTP status code is returned when an error is sent back. That should be all that is required.


Ok, you can use RKDynamicMapping to create mappings on the fly when you don't know what the keys are going to be in advance. Because the unknown keys are all keys in the same dictionary this is probably the only choice.

Upvotes: 1

Related Questions