RestKit and the key value of coding ... how to handle duplicate elements?

I have a document that sometimes looks like this:

<doc> <titleInfo> <title>One version of the title</title> </titleInfo> <titleInfo> <title>Another version</title> </titleInfo> </doc> 

But sometimes it looks like this:

 <doc> <titleInfo> <title>This is the only version of the title</title> </titleInfo> </doc> 

I am trying to match this with an array in my object with the following:

 [mapping mapKeyPath:@"titleInfo.title" toAttribute:@"titles"]; 

This works in the first case, but in the second case I get

RKObjectMappingOperation.m:199 Failed transformation of value at keyPath 'titleInfo.title'. No strategy for transforming from '__NSCFString' to 'NSArray'

It is clear that RestKit correctly interprets the first document as containing an array of strings, but in the case of the second document I cannot find a way to force this interpretation.

Is there an easy way to express this using KVC tools in RestKit, or am I better off writing some kind of fully customizable mapper?

+4
source share
1 answer

According to Blake Walters: the LibXML parser on master and in version 0.9.3 had a lot of problems and was recently replaced by the NSXMLParser solution in the RestKit development branch, and this solves some problems.

The best way is to wrap the repeating elements in an array for access.

0
source

Source: https://habr.com/ru/post/1393793/


All Articles