On 20 May '08, at 6:29 PM, Mathieu Spénard-Gingras wrote:

I was also wondering if storing data to a database is a good design pattern for Cocoa, since Apple provides something I haven't had time to look at yet: Core Data. I am simply developing a small project that will run locally on my machine, so I can get more exposure to developing with Cocoa.

You have a couple of options:

1. Store your data in non-database files. Cocoa makes this fairly easy with object archiving (NSKeyedArchiver, etc.) which is like Java's object serialization. You just make sure the classes in your object model implement NSCoding, then you can save your graph as data and write it to a file. I've done this in the past for fairly complex data with a few thousand "records", and it works reasonably well as long as you don't have to save too often (because on every save you write out the entire file.) I also have a utility library called CDBStore <http://mooseyard.com/projects/CDBStore/ > that's somewhat more efficient in that individual records get archived/loaded only as needed.

2. Use Core Data. This gives you the power of a relational database (sqlite) while still letting you manage your data as objects. (It's a bit like ActiveRecord from Ruby On Rails, or Python's SQLAlchemy.) It's not for beginners, though.

3. Use sqlite, a local SQL database library. It's small, fast and built into OS X. It stores sql databases directly in files, so there's no need for a separate server process, administering permissions, and so on. But it's a C API and you have to deal directly with constructing SQL queries. There are a few Cocoa wrappers for it, but they're still closer to the metal than Core Data.

4. Use MySQL or Postgres or Oracle or whatever. IMHO there's absolutely no need to do this unless your program is required to access an existing database server, or the db needs to be shared by multiple computers, or you need to scale to millions of records. Otherwise sqlite is great for almost any kind of single-user task.

Given your requirements and where you say you are on the learning curve, I would definitely suggest #1. I think there are some AppKit sample apps that store documents using object archives.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to