RestKit 0.20pre3 string to object mapping

208 views
Skip to first unread message

Richard Brown

unread,
Dec 12, 2012, 5:17:01 PM12/12/12
to res...@googlegroups.com
I used to be able to do this back with 0.10: Take an XML string instead of a URL and have it map to a series of objects.  I was using this to store the XML and be able to map it on the fly when needed.  This is much easier and lightweight (in my case) than having to store everything in CoreData ManagedObjects.

With 0.20pre3 the method I was using before no longer works.  Is there a comparable process now?  I can get parse to an NSDictionary using [RKMIMETypeSerialization objectFromData] but I can't figure out how to do the object mapping...

Any help would be greatly appreciated!

Blake Watters

unread,
Dec 12, 2012, 10:13:42 PM12/12/12
to res...@googlegroups.com
From an NSDictionary (or any other object really), you can initialize an RKMappingOperation and hand it an RKObjectMapping specifying how you want it mapped and it will map it for you.

If you want to map an opaque collection with (potentially) more than one object mapping, you can use RKMapperOperation, which takes the source object and a dictionary of mappings specifying the keyPaths to object mappings to use to perform the mapping.


The unit tests also provide extensive sample code

Richard Brown

unread,
Dec 12, 2012, 11:02:28 PM12/12/12
to res...@googlegroups.com
Thanks!  I was actually looking exactly in that direction before I saw your response; I'm glad I'm on the right track. :)

Richard

Richard Brown

unread,
Dec 13, 2012, 12:40:19 PM12/13/12
to res...@googlegroups.com
Got it to work, thanks!   You were right; the unit tests had valuable examples on the process.  

Richard
Reply all
Reply to author
Forward
0 new messages