Questions about NSDocuments

Discussion in 'Mac Programming' started by Duke Leto, Jul 1, 2009.

  1. Duke Leto macrumors regular

    Mar 17, 2008
    I have made a simple application already, and I now realize that it would be best to have documents. I have been reading through , 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!
  2. isharan macrumors member

    Jun 3, 2009
    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
  3. Duke Leto thread starter macrumors regular

    Mar 17, 2008
    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!)
  4. isharan macrumors member

    Jun 3, 2009
    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.
  5. Duke Leto thread starter macrumors regular

    Mar 17, 2008
    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

Share This Page