Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Core Data so difficult to prepopulate?

This is a more a philosophical question about Apple's design decisions than a question about Core Data.

Why in the world is it useful to have a model system that is so difficult to prepopulate? What are the advantages? I know you can have your program generate the sqlite file and edit it manually, but as far as I can tell, you can't do that if you have any relationships at all.

I compare this to the MVC paradigm used in rails, which seems to make way more sense. Models in rails provide a similar level of abstraction to Core Data (from what I can tell) but they also allow you to enter whatever you want into your database manually (or through a script).

The problem I have with Core Data is that: since rails seems to prove (to me) that you can have an excellent model abstraction from the database while retaining several convenient methods to prepopulate it, what possible advantages does removing that ability offer? Is Core Data somehow more efficient? Is the difficulty involved in prepopulation merely a side-effect of other design choices, and if so, why wasn't prepopulation taken into consideration?

(A disclaimer that I'm genuinely interested in the reasoning behind these choices, and though my post might suggest it, I'm not really looking for a "Models in Rails vs. Core Data" debate.)

like image 571
Evan Cordell Avatar asked Aug 02 '10 14:08

Evan Cordell


1 Answers

Because Core Data is NOT a database. It is an object graph that happens to persist to disk and one of those persistence formats is a database. This means you need to look at it in a reverse PoV.

Core Data is designed to be as fast as possible in retrieving objects from that persistent store and saving them back out. One side effect of this is that the persistent format is focused on making that goal faster and being compatible with anything else is secondary at best. Thus the internal structure of the SQLite file is aimed at performance, not at compatibility.

My opinion about pre-population is that Core Data is designed as a closed loop system. You can use Core Data to populate the data file easily. It is no harder to populate a Core Data SQLite file than it is to write a script to translate your Oracle data to CSV format.

If you stay within Cocoa and Core Data then it is not difficult at all. You write a command line app or editing app and import the data. From the PoV of a Cocoa programmer, that is a trivial task that takes just a few minutes.

like image 64
Marcus S. Zarra Avatar answered Sep 19 '22 15:09

Marcus S. Zarra