When to use CoreData in iPhone development

I'm creating a new iOS app, and after my last few apps, I was tempted to use CoreData (for benefits, including saving and auto undo / redo).

I got a little confused when trying to implement the data model that the project gave me, since it seems that CoreData seems much closer to the database than to the data model.

Should I use CoreData for an application that usually does not fit the description of “a lot of data / records”, would I usually use an SQL style database for?

If this helps, the application I'm developing will be a kind of document editor, so I will need to present several objects (the document can have embedded images, graphs / charts, hyperlinks, etc.)), and I need to create this model from the xml description.

Most of these "elements" require a set of interfaces (the model was created for a Java product, I am having difficulty with how inheritance and abstract interfaces can be applied to CoreData), and every example I have found so far seems to be Adds basic elements (such as NSDate or String) to a simple model.

Does this look like a candidate for CoreData, or is CoreData more a tool for implementing a database in an application? (i.e. in the library system / personnel database).

+4
source share
2 answers

consider CoreData as an option, as soon as you can correctly write most of the code that it replaces. therefore, as soon as you know how to serialize / deserialize correctly, write undo / redo, KVO, copy, etc.

Should I use CoreData for an application that usually does not fit “large amounts of data / records”, a description I would usually use SQL style database for?

CoreData is not limited to large databases (in general) - it will work well with small sets, as well as outside databases (binary files and documents, direct use of memory in memory).

your example might benefit from CoreData. it depends on the amount of custom code you need - sometimes just writing code if you just use CD objects as an interface generator and your application uses a lot of custom codes / objects. To be honest, I never used CoreData in a delivery application - I always found reasons to migrate models to existing code before (assuming that CoreData was also used in the development / simulation phases).

it is a good structure, but it should not be considered as a “generator of magic objects”, which will solve most problems. Firstly, you need to understand its technologies / patterns that you intend to replace with them. there are a limited number of ideal uses for it. if you cannot write the code that the objects depend on, do not use CoreData. iow - do not consider it a substitute for the initial effort, because there are certain times when it is a good choice and a bad choice - but you cannot make an objective answer for your context if you do not understand (truly) understand what it is capable of .

+4
source

One of the goals of Core Data is to control the graph of an object in memory. This is definitely suitable for your application. Then it can be easily saved to disk. With a tool like mogenerator , you can use Core Data to manage the life cycle, schedule, and persistence of objects, but add your own protocols at the top.

In short, yes, you can use Core Data to use without using a database, with a little work to fit the model.

+2
source

All Articles