Questions tagged [nsdocument]

NSDocument is an abstract class that defines the interface for documents, objects that can internally represent data displayed in windows and that can read data from and write data to files.

NSDocument is an abstract class that defines the interface for documents, objects that can internally represent data displayed in windows and that can read data from and write data to files. Documents create and manage one or more window controllers and are in turn managed by a document controller. Documents respond to first-responder action messages to save, revert, and print their data.

Conceptually, a document is a container for a body of information identified by a name under which it is stored in a disk file. In this sense, however, the document is not the same as the file but is an object in memory that owns and manages the document data. In the context of the Application Kit, a document is an instance of a custom NSDocument subclass that knows how to represent internally, in one or more formats, persistent data that is displayed in windows.

A document can read that data from a file and write it to a file. It is also the first-responder target for many menu commands related to documents, such as Save, Revert, and Print. A document manages its window’s edited status and is set up to perform undo and redo operations. When a window is closing, the document is asked before the window delegate to approve the closing.

NSDocument is one of the triad of AppKit classes that establish an architectural basis for document-based applications (the others being NSDocumentController and NSWindowController).

References:

NSDocument Class Reference

479 questions
4
votes
2 answers

NSDocument unique identifier

Q: Is there any way to acquire unique identifier of NSDocument in Document-based™ application which is persistent during app restarts? Note1: there definitely should be some kind of id which is not just fileURL, but something else because app…
kisileno
  • 787
  • 9
  • 23
4
votes
2 answers

Document-based application, or not?

I'm writing a desktop app that could be used to manage a dance academy. My Core Data model contains such entities as Student, Teacher, Class, Invoice, etc along with the various relationships between them. My planned UI consists of a vertical…
Craig Edwards
  • 2,118
  • 1
  • 18
  • 23
4
votes
1 answer

Rename Document class in Swift document-based application

I am building a new document-based application in Swift for OS X using Xcode. I would like the default Document class to be called something that is not Document (in this case Notebook), though of course it would still subclass NSDocument (or…
Displaced Hoser
  • 871
  • 3
  • 13
  • 35
4
votes
1 answer

Access NSDocument from NSViewController and vice versa

What is the correct way to access the NSDocument subclass from its associated NSViewController subclass and vice versa? I have the following code that does the former, but it doesn't work when the view has loaded or when it moved to a window: var…
4
votes
0 answers

Using NSDocument for Packages without NSFileWrapper

I want to create a package with multiple directories containing media data (audio and video) which I then load as AVURLAssets. As AVURLAssets are created with an URL, I can't use (as far as I know) NSFileWrapper. The documentation states that…
thomasguenzel
  • 670
  • 7
  • 25
4
votes
0 answers

Set size of NSView/NSDocument

I'm making an app that is modeled after the Sketch example program. I've rewritten Sketch in swift (it was a great way to learn the language) and everything works fine. However, in this app, I want the document to be fixed size, different from the…
4
votes
4 answers

Printing an NSDocument

I'm trying to print a document. The document is an array of NSImageReps, or a single NSPDFImageRep, which has multiple pages. I'm having trouble figuring out how to use the NSPrintOperation class to print this. The NSPrintOperation seems to need…
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
4
votes
1 answer

When should I extend NSDocument and when should I extend NSWindowController?

I've an application that holds a main window with a list of items, and from that window an undetermined number of windows can be opened. Each of those windows can hold several instances of a model object, with those instances listed in a drawer. I…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
4
votes
1 answer

Zoom window for new documents to full screen

This should be straightforward but I couldn't find anything on either SO or Google on this topic so.. What's the best way of zooming new document windows to full screen (i.e. not the full screen mode but just maximizing the window) for NSDocument…
ATV
  • 4,116
  • 3
  • 23
  • 42
4
votes
1 answer

Detect overwritten file using NSDocument

I have an OSX app which uses NSDocument and autosaves inplace - all works well. Sometimes the user will save the document into a Dropbox synced folder and there is then the chance that the document will be updated (via Dropbox) whilst its still open…
Scotty
  • 2,019
  • 1
  • 20
  • 31
4
votes
2 answers

Keeping and NSDocument open without any windows

I have a document-based application which has two document types. The first NSDocument subclass is the "main" document (mainDoc) and it's .xib file is the main editing window for the application. The second NSDocument class is a data source file…
Tangler
  • 168
  • 9
4
votes
1 answer

How to prevent a document-based cocoa application to open ANY document?

Recently, a document that was saved caused a crash whenever I would start my app. Is there a way to prevent a doc-based app from opening any document, including a new empty or the last active document(s)? I'd like to do that not by using OSX…
Carelinkz
  • 936
  • 8
  • 27
4
votes
1 answer

Debug NSDocument app at startup via file drag-and-drop?

Suppose I have an NSDocument app that supports dragging-and-dropping of a file onto its icon to launch the app and open that file. My NSApplicationDelegate has implemented - (BOOL)application:(NSApplication *)sender openFile:(NSString…
JefferyRPrice
  • 895
  • 5
  • 17
4
votes
3 answers

How to disable the auto-reopening of the last document?

How to disable the auto-reopening of the last document ? When I execute my application, it calls the method readFromData. But, the problem is that between my version 1 and my version 2, I changed the structure of the data that is saved by the…
Colas
  • 3,473
  • 4
  • 29
  • 68
4
votes
0 answers

Apple sandbox: Disable NSDocument's atomic save for Document-scoped bookmarks

I have posted this question on Apple's Developer forum and received no reply after a week, so I am hoping I will have better luck here. I have created a standard document-based application (using NSDocument, saving simple XML files) that I now need…