Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FMDB Wrapper VS Core Data : Which is easier to Use & Maintain? [closed]

FMDB Wrapper VS Core Data : which is easier to use & maintain?

I am confused because FMDB is very old but still many developers are using it, while Core Data is new and is only supported by 3.0 and later sdk.

Some have said that FMDB is easy to use and some said Core Data. Please help me so I can go in the right direction.

Thanks in Advance

like image 856
freelancer Avatar asked Dec 17 '11 05:12

freelancer


People also ask

Should I use Core Data?

The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

What database does Coredata use?

Core Data can use SQLite as its persistent store, but the framework itself is not a database. Core Data is not a database. Core Data is a framework for managing an object graph.

Is Coredata a relational database?

Core Data is not a relational database or a relational database management system. It can use SQLite as one of its persistent store types, but it is not in and of itself a database. You could set up Core Data to just use an in-memory store just to get the change tracking and management features without persistence.

What is FMDB in IOS?

FMDB is an Objective-C wrapper around the C-style API provided by Apple for SQLite. It's important to note the SQLite is not an Apple proprietary technology. SQLite is an open source C-language library used by Apple, Android, Skype, and many other clients and applications to provide a robust database engine.


1 Answers

I have used both heavily across a lot of projects now.

FMDB is very straightforward, if you know SQL it can even be pretty easy to use. But what you have to do through the lifecycle of an app as the data model changes is:

  1. Change the data model, typically with something like Base
  2. Change SQL code to reflect model changes
  3. Change data objects to reflect model changes
  4. Add code into app to handle case where you encounter the older database.

What Core Data brings to the life cycle is this:

  1. Data model and objects are changed with the same action (I'm assuming you generate data objects with something like mogenerator).
  2. Easier visualization of data model.
  3. Encourages easier to traverse data models by making you think about inverse relationships.
  4. Often auto-migration is enough to transition through simple model changes without having to rebuild the DB from scratch.
  5. Core Data offers some iCloud integration via NSManagedDocument.

The hell that Core Data puts you through is:

  1. Deletion sucks, because any access of properties in a deleted object throws a program killing exception.
  2. Background thread data access sucks, because Core Data makes it complex to work properly with multiple threads - you cannot for example use a data object you obtained from a context in one thread in another different thread. So much for simply passing objects to background threads for work with...
  3. There is so much magic swirling around your data that WHEN things go wrong it will be terribly frustrating trying to figure out what to do.
  4. Core Data seems terribly fragile, things like the deleted objects throwing exceptions, using from the wrong thread throwing exceptions, validations throwing exceptions, or the whole model vanishing after what seemed like a simple change are all possibilities.

So what would I recommend? To paraphrase the old quote about Democracy, Core Data is the worst data persistence system - except for all the others. Even with the new definition of pain and suffering that Core Data will bring to your life, it is still less work and easier to work with than FMDB or other data persistence layers.

FMDB is more straightforward and if you are OK putting lots more time into changes and data model definition that may be OK. But generally I would recommend people bite the bullet and use Core Data unless there is a clear reason not to.

A few quick tips:

  • Never delete anything in Core Data while the UI is up and possibly accessing objects.
  • If possible treat the database as disposable and be able to rebuild content, so that if automigration does not work the user can still run the app.
  • Keep all Core Data activity on the main thread and only put in the background as a last resort.
  • Do not under any circumstance use Core Data validations, or ever uncheck the "optional" box foray field in your entities. Which would you rather have, a bad value slip into your model that may end up displaying funny or the app simply crashing?
  • Use mogenerator to generate data objects from your model. It outputs objects that are directly tied back to the model that re-generation can change, and a layer of objects sort of "above" that that start out blank but into which you can add custom logic around the data objects and will not be altered when the lower objects are regenerated.
like image 119
Kendall Helmstetter Gelner Avatar answered Nov 10 '22 20:11

Kendall Helmstetter Gelner