开发者

Coredata and SQLite

I am new to programming with Objective-C. I don't understand the concept 开发者_如何学JAVAof "core data" -- can someone suggest any good resource(s) to learn about "core data" (and also SQLite)? Any help will be appreciated.


The most important advice I can give is to not confuse Core Data with SQLite or SQL in general. Because Core Data can use SQLite as one, but only one of several, persistence methods, a lot of novices develop the idea that Core Data is just an object oriented wrapped for SQL and that therefore Core Data can be understood in terms of SQL e.g. tables, columns, rows, keys, joins etc. However, Core Data really has nothing to do with SQL and really nothing you know about SQL applied to Core Data.

SQL and Core Data approach data from exactly opposite directions and that trips people up.

SQL is largely concerned with getting data onto and off a persistent store (usually a drive.) What the program does with the data once it's been read in isn't SQL's concern.

Conversely, Core Data is largely concerned with managing live objects in memory during runtime. It is primarily concerned with modeling/simulated the real world objects, events or conditions that the program deals with. 90% of Core Data work is associated with this modeling and persisting the data (SQL main task) is really just an after thought. In fact, you can use Core Data with out persisting anything (using in-memory store) if you want.

Novice Core Data programmers with SQL backgrounds waste a lot of time trying to figure out how Core Data implements all the SQL stuff when in reality Core Data does it all in the background and only if you use an SQLite store in the first place.

The best perspective to adopt when learning Core Data is to completely ignore that the data may be persisted at all. Instead, adopt the perspective of Core Data managing the in-memory runtime managed objects and their relationships with no concern to how or if they will ever be saved. From that perspective, Core Data is revealed not as a database but as a data modeling tool. That will put your attention where it belongs, on the data and the relationships between the data and that in turn will make Core Data's implementation details much easier to understand.


Probably sounding a bit harsh, but have you had a look at the Core Data documentation?

There is the demonstration from Cocoa Dev Central.

And here as Matt Gallagher explaining the difference between Core Data and a database

That should get you started enough to ask more specific questions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜