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

How to automatically create new NSDocument if no documents are restored?

EDIT: It seems like the issue below only occurs (rather, fails to occur... :) when I run the from within Xcode (I'm on 4.4), rather than from Finder. Is this an Xcode bug, or am I missing something? I want to create a new (untitled) NSDocument when…
3
votes
2 answers

NSNotificationCenter in document-based app

I'm using NSNotificationCenter to send custom notifications in a document-based app. A document-based app can have many open documents. Ideally, I would like the the document and its children to receive only the notifications created within the…
hpique
  • 119,096
  • 131
  • 338
  • 476
3
votes
3 answers

How to access an object's NSDocument?

I can access an app-wide delegate instance using [NSApp delegate] after adding an NSObject to the mainmenu.xib, setting the name of the object to the name of my appDelegate and setting the mainmenu.xib delegate to this object. Now, what I would…
Carelinkz
  • 936
  • 8
  • 27
2
votes
2 answers

NSDocument Versions has weird behavior

Saving and Opening of file works perfect, but when selecting 'Revert To Save', on the right side of windows (previous documents) for a blink of second my document versions are seen then just blank copies. And if I restore from this blah copy noting…
Raj
  • 41
  • 5
2
votes
2 answers

Showing a non-modal template chooser synchronously

I'm writing a Cocoa app using the document architecture. Whenever an untitled document is created in this app, the user should be shown a window that lets them pick a template and prompts for other information. Only one of these windows should show…
Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
2
votes
1 answer

How to edit many documents in one window with the nsdocument architecture

I am writing a document based application, where there is a project file that the user opens, and a number of associated source files, all of which I wish to edit in the same window. How can I do this within the NSDocument architecture?…
Duncan
  • 443
  • 1
  • 5
  • 12
2
votes
1 answer

How to add "normal" NSDocument logic to a modified project-based architecture?

I am planning to create a project-based Mac application. It has its own project file format and is currently able to read and handle it. That's already the problem of the whole story: I open the project file and not the files each by…
Paul
  • 1,295
  • 2
  • 11
  • 26
2
votes
0 answers

iCloud Drive: NSDocument.revert(toContentsOf:ofType:) called when document is merely opened on another device

I have a macOS and iOS app, based on NSDocument and UIDocument respectively. They synchronize their documents via iCloud Drive. I noticed that NSDocument.revert(toContentsOf:ofType:) is called on the Mac when a document is merely opened in the iOS…
Mark
  • 6,647
  • 1
  • 45
  • 88
2
votes
1 answer

Determine which button pressed in Save Panel in NSDocument based application

How should I determine which button is pressed (save, Cancel) when the save dialog is dismissed in an NSDocument based application ? The save panel is the default provided by NSDocument when save is selected from menu. I would like to have the…
Vassilis
  • 2,878
  • 1
  • 28
  • 43
2
votes
3 answers

Bring all NSDocument windows to front when opened

In most systems, the default behaviour for "open a new window" is that it appears at the front. This doesn't happen in Cocoa, and I'm trying to find the "correct" way to make this standard behaviour. Most things I've tried only work for a maximum of…
Adam
  • 32,900
  • 16
  • 126
  • 153
2
votes
4 answers

NSDocumentController.openDocument not allowing selection of custom file type

I suspect this is a finicky configuration issue that I'm getting wrong with Document Type / UTI declarations in my Info.plist, but have tried several things and haven't found the solution. I have an NSDocument-based Mac application, written in…
Corbell
  • 1,283
  • 8
  • 15
2
votes
4 answers

Sharing NSDocument subclass between multiple NSWindowControllers

I have a application that isn't currently a document-based application (because I thought it would be more trouble than its worth). However I've been thinking it may possibly be worth it now, but there is one issue I haven't worked out yet. Sharing…
Joe Boo
  • 105
  • 3
  • 10
2
votes
1 answer

What is the correct way to open a file from line arguments in an NSDocument application in Swift?

I'm working on a MacOS Document based application that opens a certain file type. What I want to do is write some UI tests for this application, but I want to load some mock data for these UI tests. From what I understand, I should actually use…
chadsmitth
  • 23
  • 3
2
votes
1 answer

In a macOS Cocoa Document-Based Application what could be a good implementation strategy for a "New From Template" feature like for example in Logic?

Thanks in advance for your help. I have a good experience on macOS applications, but I am almost new in regard to document-based apps. I am trying with a new project that is document-based and uses CoreData. I would like to implement a "New Document…
Alfonso Tesauro
  • 1,730
  • 13
  • 21
2
votes
1 answer

How to invoke a Selector in Swift with more than 2 arguments

I'm overriding NSDocumentControllers reviewUnsavedDocuments(withAlertTitle:cancellable:delegate:didReviewAllSelector:contextInfo:) in Swift. The documentation says that the didReviewAllSelector has this signature, note it has 3 arguments: -…
Craigt
  • 3,418
  • 6
  • 40
  • 56