My team and I have been working on an existing, non-document-based Cocoa application. This is our first Cocoa app, although we've done a number of iOS apps thus far.
The app really should be document-based, though, so I've begun trying to convert it. But things here & there don't seem to be working. For example, the File -> Open menu item is permanently disabled (although I finally got the File -> Save menu item to enabled; initially it wouldn't). In addition, I can click the red X to close a window, although the File -> Close menu item itself is disabled; however, when I close the window via the X button, the dealloc method in my NSDocument implementation (SPDocumentInfo) is not invoked. I created a sample, brand-new document-based app just for comparisons; when I close a window there, the SPDocument implementation's dealloc method is indeed invoked (as I'd expect.) So that concerns me.
I made a lot of changed to the project here and there; they include:
Made SPDocumentInfo extend SPDocument like so in the .h file:
@interface SPDocumentInfo : NSDocument <NSWindowDelegate>Implemented the following in SPDocumentInfo:
- (NSString *)windowNibName { return @"SPDocument"; } - (void)windowControllerDidLoadNib:(NSWindowController *) aController { [super windowControllerDidLoadNib:aController]; } - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { NSString *xml = [self toXml]; return [xml dataUsingEncoding:NSUTF8StringEncoding]; } - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { // will make this work later if ( outError != NULL ) { *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; } return YES; }Edited the .plist file to add "Document types". Among other things, defined "Cocoa NSDocument Class" = "SPDocumentInfo".
Altered some connections in SPDocumentInfo to match the connections in the sample document-based app. For example, in SPDocument.nib, the File's Owner (which represents SPDocumentInfo) is the Window's delegate.
So, I'm wondering if there are other sorts of things I might be missing in converting to a doc-based app. Or, are there any guides on how to do this? (I've looked but couldn't find any). Or should I just start over with a new document-based app and try to retrofit all of our stuff into it? In general, does anyone have any experience with this?