aryaxt / OCMapper

Objective-C library to easily map NSDictionary to model objects, works perfectly with Alamofire. ObjectMapper works similar to GSON
MIT License
347 stars 45 forks source link

Array of Custom objects #45

Closed abduranjum closed 8 years ago

abduranjum commented 8 years ago

I have an array of treatments. The class name is ICATreatment. The mapper maps the array to dictionary correctly, but fails to map from dictionary to array.

aryaxt commented 8 years ago

I need more information. If the array is nested to another object and the property name doesn't match the class name you need to write mapping. There are samples covering all cases here:

https://github.com/aryaxt/OCMapper/blob/master/OCMapperTests/ObjectMapperTests.m#L184

abduranjum commented 8 years ago

It maps ICATreatment if is a simple property, but fails if it is in an array.

aryaxt commented 8 years ago

if the property is named icaTreatment it would map it automatically, otherwise you need to write mapping. this is only needed for arrays since the runtime API can't tell the types of objects in an array.

[inCodeMappingProvider mapFromDictionaryKey:@"treatments" toPropertyKey:@"treatments" withObjectType:[ICATreatment class] forClass:[PARENT_CLASS class]];

There is example of this on readme

abduranjum commented 8 years ago

I could not find this example in the readme file. But it is working now after using the mapping you gave. I did that mapping before, but was wondering why it was needed, as the mapper could map the simple property, so I thought it would map the array also.