PDA

View Full Version : Questions about NSDocuments




Duke Leto
Jul 1, 2009, 08:37 AM
I have made a simple application already, and I now realize that it would be best to have documents. I have been reading through http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/SubclassNSDocument.html#//apple_ref/doc/uid/20000028 , and I started to wonder about how a document structure would fit into my code.

First of all, is it possible to have only one window, open, thus allowing only one document to be open at a time?

If that is not possible or not recommended, should I separate my window that displays the document from the nib that has the mainmenu data?

I have a NSObject subclass that controls about everything in a window. Other than simply saying it is a subclass of NSWindowController, are there any methods I need to subclass?

What kind of data can be stored? Is it possible to have a .plist kind of thing, with an array and a few numbers?

Any advice for switching to an NSDocument Application is welcomed!
:cool:



isharan
Jul 1, 2009, 03:50 PM
I have made a simple application already, and I now realize that it would be best to have documents. I have been reading through http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/SubclassNSDocument.html#//apple_ref/doc/uid/20000028 , and I started to wonder about how a document structure would fit into my code.

First of all, is it possible to have only one window, open, thus allowing only one document to be open at a time?

If that is not possible or not recommended, should I separate my window that displays the document from the nib that has the mainmenu data?

I have a NSObject subclass that controls about everything in a window. Other than simply saying it is a subclass of NSWindowController, are there any methods I need to subclass?

What kind of data can be stored? Is it possible to have a .plist kind of thing, with an array and a few numbers?

Any advice for switching to an NSDocument Application is welcomed!
:cool:

If you want to only have one window open, why make it a document-based application? There are really no advantages to switching to NSDocument if you only want one window open...kinda defeats the purpose of the whole thing

Duke Leto
Jul 1, 2009, 05:16 PM
Yeah, i guess you are right. I just wanted a save capability, without having to deal with more than one window.

BTW, I came up with another question.

That nib had a controller that did just about everything, and now I realize that that class can become an NSDocument subclass. However, how do I keep the connections between buttons/MainMenu if there are more than one?

Should I subclass NSDocumentController and pass the events down?
In other words, I need to keep the nib connections in some way while adding save/new/open functionality.

If someone needs a visual, I can post a .zip of the app (be careful, there is a memory leak!)

isharan
Jul 1, 2009, 06:48 PM
Yeah, i guess you are right. I just wanted a save capability, without having to deal with more than one window.

BTW, I came up with another question.

That nib had a controller that did just about everything, and now I realize that that class can become an NSDocument subclass. However, how do I keep the connections between buttons/MainMenu if there are more than one?

Should I subclass NSDocumentController and pass the events down?
In other words, I need to keep the nib connections in some way while adding save/new/open functionality.

If someone needs a visual, I can post a .zip of the app (be careful, there is a memory leak!)

There are ways to do save without using NSDocument. I guess if you want to keep your existing nib connections, then yes, just use NSDocument to pass the events down.

Duke Leto
Jul 1, 2009, 07:25 PM
Basically, I could have an object that receives the input and tells the correct document what to do by something like this.


- (IBAction)doSomething:(id)sender
{
[[NSDocumentController currentDocument] doSomething];
}


And this could be connected to the nib. Seems like kind of a waste, but I'll do it.

As for actually reading/writing, I think I would use an XML document. Where can I find help managing those kinds of documents?
Meh, I'll figure it out with documentation.

Thanks for the help :D