I read data from an xml file, and the simplified NSDictionary is looking like this:
{
Name = "Song Title";
Album = "Album Title";
"Album Artist" = "Album Artist Title";
Artist = "Artist Title";
}, ...
I want to make models ITSong, ITArtist, ITAlbum, and so on.
The structure should be smart, so I could expand it with ITComposer, or whatever.
The problem is that the models are nested.
The ITArtist should hold an array of ITAlbums, and an ITAlbum should hold an array of ITSongs.
This would require a bunch of nested for-loops, checking for unique NSStrings for the specific keys, and would have to be repeated for the album, the artist, the album artist, and so on. Which doesn’t seem like a very good solution.
Instead of reinventing the wheel, I want to check if there is a library that can do this.
How can I map a complex NSDictionary to custom models the right way?
Thanks.
RestKit (http://restkit.org, you’ll need https://github.com/RestKit/RKXMLReaderSerialization as well) does a good job of deserializing XML and JSON into Objective-C classes. You define the relationship between the XML and the classes and it will automatically create the objects.