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
0
votes
1 answer

My NSDocument read method isn't being called

I'm writing a Cocoa Document based app. I've gotten it to the point where it can save a document using override func data(ofType typeName: String) throws -> Data { // End editing let jsonEncoder = JSONEncoder() let jsonData = try…
0
votes
1 answer

Cannot quit the app if I cancel the save operation in a NSDocument

I'm subclassing the NSDocument class in order have a specific behavior during the save. I save the project in a folder and I create specific sub-folders with audio files used for this project. I override the following function…
DEADBEEF
  • 1,930
  • 2
  • 17
  • 32
0
votes
1 answer

Disable NSDocument's "Revert To" & "Duplicate" menu item

I am creating a Mac app to read a XML document and save it. Everything is working fine except "Revert To" & "Duplicate" menu items. Till i find a solution for that i want to disable both of them, but i didn't found any solution for it, Please let me…
Shiva Kumar
  • 389
  • 3
  • 22
0
votes
1 answer

Strange loadNibNamed behaviour

I have a document-based Cocoa app. During runtime, I load an additional nib from the bundle by invoking [NSBundle loadNibNamed:@"inspectorNIB" owner:self] (where self is the NSDocument). Strangely enough, while loading the bundle succeeds, it…
Marcel Hansemann
  • 1,019
  • 8
  • 11
0
votes
1 answer

autosavedContentsFileURL is nil after successful autosaveWithDelegate

I am having a heck of a time getting NSDocument's autosave to work. I have a NSDocument subclass that takes some user input and computes (generates) a coverTree for that data. Upon completion, I am attempting to autosave the document to capture…
MikeMayer67
  • 570
  • 6
  • 17
0
votes
1 answer

encodeRestorableState for unsaved documents

The documentation for NSDocument states: Subclasses can override this method and use it to restore any information that would be needed to restore the document’s window to its current state. For example, you could use this method to record …
MikeMayer67
  • 570
  • 6
  • 17
0
votes
0 answers

URL based document saving

I have a prototype project of url based documents, where I cache document info to user defaults. User actions tally the change count which I'd like to autosave - once I figure out how, so an explicit close triggers the standard dialog to save first.…
slashlos
  • 913
  • 9
  • 17
0
votes
1 answer

Window title document icons that do not appear

I'm trying to understand the basis by which a document's window title presents a panel (save?) and contextual menu. I created a project where a new document shows the "v" (down caret) to access what appears to be save panel: But why wouldn't these…
slashlos
  • 913
  • 9
  • 17
0
votes
1 answer

After changing Document Parameters, NSCocoaErrorDomain 256 opening *new* docs

For the next version of a NSDocument-based app, I am revising the document parameters, that is, the values in Info.plist > CFBundleDocumentTypes and UTExportedTypeDeclarations. Specifically, I am changing from a flat NSPersistentDocument to a…
Jerry Krinock
  • 4,860
  • 33
  • 39
0
votes
1 answer

Prevent NSDocument's auto-saving while its content is editing

I develop a document-based Cocoa application allowed saving documents asynchronous. Namely, my NSDocument subclass returns ture on canAsynchronouslyWrite(to:typeOf:for:). I want dynamically and silently delay (or cancel) regular auto-saving if the…
1024jp
  • 2,058
  • 1
  • 16
  • 25
0
votes
0 answers

How to set up an NSView for printing?

How can an NSView be set up for printing? For example, say I have a view in which I've overridden layout() to lay things out just as text does, flowing from one line to the next according to the width of the view. Nothing should scale, and the…
arsenius
  • 12,090
  • 7
  • 58
  • 76
0
votes
1 answer

EXC_BAD_ACCESS when closing NSDocument window (ARC enabled)

I'm working on converting a document-based application from Garbage Collection (it ran fine under 10.6) to Automatic Reference Counting (trying to get it to compile and run for 10.12). I'm getting a consistent EXC_BAD_ACCESS when the last window is…
0
votes
1 answer

setTitleWithRepresentedFilename not changing NSWindows filename?

I have a NSDocument that I am calling: [self.windowForSheet setTitleWithRepresentedFilename: @"hello"]; On, but the windows title does not change. It displays MyApp -- Untitled 1. I have also tried: [self.windowForSheet…
Kyle
  • 17,317
  • 32
  • 140
  • 246
0
votes
1 answer

How to bind an array controller to a NSDocument array property?

I'm having trouble figuring out the right way to bind an NSArrayController (in turn bound to by a table view) to an NSArray property of an NSDocument instance via a view controller. My NSDocument subclass has a property NSArray * pages. I first…
0
votes
1 answer

(Why) Should I keep a pointer to the FileWrapper in the open document?

I have a working document based project with both iOS and macOS targets. The document is a bundle and I have each target able to open files from the other. I was looking at some online tutorials on UIDocument (and particularly this one from…
Jef
  • 4,728
  • 2
  • 25
  • 33