views:

1971

answers:

2

Hi,

I´ve created an utility Application which is nearly complete, but now I´m on a point were I really have to persist Data. Since XCode provides only Core Data Templates in an Navigation or Window Based App, is there an easy way to add Core Data to my Application? I´ve never worked with Core Data and just have to persist messages with 460 Characters and a contact Name tp it as a history of send Messages.

Or should I start with a new Window Based Application incl. Core Data and try to build the Utility / Flipside Part by hand?

Can someone suggest me the best practice for my situation?

Thank you

twickl

+5  A: 

You'll need to add the CoreData framework to your target, create a data model, and instantiate the NSManagedObjectModel, NSPersistentStoreCoordinator, and NSManagedObjectContext objects.

Adding Core Data to an existing application is discussed briefly in this Apple document (search for "existing application")

You should also view the Apple tutorial to get a feel for what is involved.

You can always consider just using SQLite as well.

nall
I agree with the idea of using SQLite instead. Core Data is pretty heavy duty and since it sounds like there isn't much data or any complex relationships being persisted here, SQLite might be the less complex, more efficient way to do this.
Marc W
Core Data is easier though, once you understand how it works - this is especially true for small projects.
Kendall Helmstetter Gelner
I would vote against rolling your own code directly against SQLite. All such code I have ever seen have just re-implemented parts of Core Data, but in a buggy and even less preferment way. Core Data is the way, especially when bindings are added to Cocoa Touch down the road.
PeyloW
I echo what PeyloW said regarding rolling your own code. If you do choose SQLite, read this: http://stackoverflow.com/questions/874830/best-sqlite-practices-on-the-iphone
nall
+3  A: 

Create a new project in XCode, using the templates provided - find one that has a box to check for using Core Data for storage.

That gives you an xcdatamodel file, and some code/class variables in the application delegate that you can copy from that project into your current one.

I also highly recommend the Apple tutorial mentioned by nall.

If you do decide to just use SQLLite directly instead, strongly consider using FMDB, which simplifies SQL code. It's one file you add to a project.

Kendall Helmstetter Gelner
The tutorial was mentioned by *nall* not *nail* :)
Timothy Walters
I highly recommend FMDB as well if you're going to use SQLite.
Shawn Craver
Could have sworn that was an "i". Thanks Timothy! Fixed.
Kendall Helmstetter Gelner