Question

as a developer I face with processing data each day. The common thing that I need to process the raw data to the object (NSManagedObject). So I am using AFNetworking for getting data from the remote server and as a result of AFNetworking work I have a data that can be represented by NSDictionary. So the main thing that can take a lot of work it is converting this raw data to concrete data models. So there are many libraries in the Internet that can do this hard work for us:

MagicalRecord MagicalImport

Mantle

EasyMapping

So as a new in mapping I want to know which library is the best for my purposes. Maybe you can suggest another one as well.

Was it helpful?

Solution

Each of the libraries you mentioned have different purposes:

MagicalRecord - simplifies common Core Data operations (fetching, inserting, deleting, setting up the stack, etc.). It does not handle mapping JSON or any other format to Core Data models. Correction thanks to @casademora: MagicalRecord can handle imports with custom mappings using the steps described here. That said, MagicalRecord is a rather large library to use just for this piece of functionality.

Mantle - greatly reduces boilerplate for model objects in Objective-C (automatic implementations of NSCoding, NSCopying, -isEqual:/-hash, etc.). Includes adapters like MTLJSONAdapter and MTLManagedObjectAdapter for converting between representations of model obejcts. This sounds like it's the best fit for what you're trying to achieve. If you implement both the MTLJSONSerializing and MTLManagedObjectSerializing protocols on your MTLModel subclass you will be able to turn NSDictionary responses from the web API (presumably JSON data) into Core Data model objects.

EasyMapping - I haven't used this library myself, but it looks like its provides a small subset of Mantle's functionality purely for converting between various model representations, except that it uses mapping models (EKObjectMapping) instead of subclassing a base model class. The disadvantages of using this library would be that it doesn't handle any of the other Objective-C model object boilerplate for you like Mantle does.

Out of the 3 libraries mentioned, I think Mantle would probably be the best fit for what you described. Another option is to use RestKit, which provides tighter REST API/Core Data integration than any of these libraries, but is significantly harder to use and debug.

OTHER TIPS

If you need close Core Data integration you should look at RestKit (http://restkit.org) If you do not - I suggest EasyMapping. It is very easy and powerful enough for almost all situations. It is also not requires to subclass your classes from framework class (like MTLModel in Mantle)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top