views:

167

answers:

2

Hi, everyone. I've been experimenting with Cocoa and Objective-C programming on the Mac for a few months now, and I am wanting to start developing applications that manage large amounts of data. The trouble is, I'm not really sure where to start with databases.

I have a good background in Java programming with SQLite. I've read a bit about CoreData and I haven't been able to find any good resources for just manually connecting to the database. I'm looking for recommendations.

Should I try CoreData, and if so, can anyone recommend a good tutorial for someone new to the language? Or, should I try to manually connect and query an SQLite database somehow, and, if so, any tutorials? Any help would be greatly appreciated!

Thanks!

+4  A: 

Check out the supremely awesome Flying Meat Database. It's an Objective-C wrapper around the C SQLite API and makes it really really easy to deal with SQLite databases in Cocoa.

Oh, and it comes with some sample code, which is pretty easy to understand and is decently commented. Chances are that 99% of anything you'd want to do with a SQLite database are demonstrated in the example.

In my opinion, if you use anything else to access a SQLite database (that's not a CoreData store), you're doing it wrong.

Dave DeLong
That's severely lacking in documentation. Got any other helpful links? (RTFS is all very well, but doesn't help guide towards the *best* way to use an API…)
Donal Fellows
@Donal if by "lacking in documentation" you mean "it doesn't have a docset or anything", then yes. However, did you even look at the sample code? It's pretty straight-forward...
Dave DeLong
@Dave: Samples… I guess I prefer a bit more depth to my docs than that. (Yes, I still write manpages.)
Donal Fellows
Thanks, Dave. I'll defiantly check that out. A friend of mine who I'm doing development with has been having the same problem and was wondering if we should try using C. This sounds like the thing to use. I never was a big fan of traditional docs so hopefully that won't affect me.
Jesse
Okay, this defiantly looks like a good option, after inspecting the sample code, it seems pretty straightforward. I downloaded the source files and got everything imported correctly to my knowledge but I'm getting stopped by the pesky "Compiler exited with code 1." I'm planning on investigating this more tomorrow when I can devote some more time to this, but does anyone know what could be causing this off hand? Sorry I can't offer more details as I'm not able to get to my computer right now. Thanks for any and all support!
Jesse
You have to make sure that you link against libsqlite.3.dylib in your target's "Link binary with libraries" phase.
Dave DeLong
Okay, so I was able to get to my computer today. From what I understand, I need to add the libsqlite3.dylib by way of right clicking, Add > Existing Frameworks. (I hadn't even tried this yesterday, stupid mistake on my part) I find the libsqlite3.dylib file and add it. In the Target area under "Link binary with libraries", it shows the libsqlite3.dylib. Is this how it's supposed to be? Anyway, when I try to compile, it doesn't even compile the files, it just fails with exit code 1 immediately. Sorry if I'm missing something obvious and thanks for all of your help so far.
Jesse
Sorry, after I posted this, I realized I was accidentally adding the sample code file from the src directory in fmdb. This had a second _main which was causing the "Exit code 1". I've removed it and everything is working great now. Thank you so much for all of your help. I really appreciate it!
Jesse
+2  A: 

Apple has several Core Data tutorials like this: http://developer.apple.com/cocoa/coredatatutorial/index.html

If you want to use sqlite, just use the sqlite C API: http://www2.sqlite.org/cintro.html

Ken Aspeslagh
In light of what Dave said, I will add that for anything other than a few simple commands, don't use the sqlite C API ;)
Ken Aspeslagh
Thanks, Ken. I've read a few of these Core Data tutorials. I think I need to devote some time to just sitting down and really reading them. It seems like every time I've tried, I get lost, usually because of something outdated. All of the Core Data tutorials I've read seem to be for older versions of XCode, which doesn't help for a beginner! Thanks again for the help though!
Jesse
My suggestion would be to get in there and actually use Core Data for simple project. Once you get in there and use it once, you'll get it.
Ken Aspeslagh