NSDocument app where the document is a SQLite file
NSDocument app where the document is a SQLite file
- Subject: NSDocument app where the document is a SQLite file
- From: email@hidden
- Date: Tue, 07 Dec 2010 11:13:52 -0500
I've written a few small personal Mac apps and one iOS app and now am attempting to write my first NSDocument-based Mac application. I would like the document itself to be a SQLite file (with specific tables for my app - not a generic SQLite file). I've been reading through the NSDocument documentation and it appears this can be done, but I'm not 100% certain of the steps and wanted to make certain I wasn't going down a path I shouldn't before getting too far into it. Here is what I think I need to do:
Here's what I think I need to do in my NSDocument subclass.
When the user chooses a File->New, the method - (id)initWithType:(NSString *)typeName error:(NSError **)outError is called so in it I would create a SQLite database file in a temporary location and call setFileURL: to store the location of that SQLite file (and store a connection to the SQLite database file).
In the - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError, if the passed absoluteURL matches the return value of fileURL: I would do something like commit the SQLite transactions. If the absoluteURL did not match the returned value of fileURL: I need to copy the current SQLite file to this location. Will this work ok?
In the - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError I would just open the SQLite file and store my connection to it for use in the other methods for updating the file.
Am I missing something? Is attempting to use a SQLite file as the document file a bad idea?
I'm also considering an iOS application that uses the same SQLite database files so that's why I'd like to use SQLite on the Mac if possible. I'm also not ready to tackle using Core Data although that may be the better option if there are reasons that SQLite doesn't map well to a NSDocument based application. My other option is to not use the NSDocument architecture, and just open one file at a time in my GUI but I thought I'd try to learn about the NSDocument architecture while writing it.
Thanks,
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden