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

Undo troubles: Initialise `NSPersistentDocument` programmatically without "edited" flag in title bar

I have a small app using core data and NSPersistentDocument. For new documents I initialize the document with a single Settings element. I already could suppress the undo entry generated by the initialization, but... The strange behaviour is this:…
Flovdis
  • 2,945
  • 26
  • 49
3
votes
0 answers

OSStatus error -4

I am creating document based app and I have strange problem - I can't open files which I saved. Each time I receive this error: "The document /name/ could not be opened". Here is output from NSError: The operation couldn’t be completed. (OSStatus…
Gun13
  • 103
  • 9
3
votes
1 answer

NSDocument vs sqlite records

I'm developing a cocoa application that could be used to manage customer and employee details in a small business. When I read through the NSDocument architecture, I believe that the document/window management and workflow it gives you is…
reds2010
  • 31
  • 1
3
votes
1 answer

NSDocument opening over a default document

I'm writing a NSDocument-based application in Swift. I have set it to open a default document if the application is not started with a document parameter. I've noticed that if I start the app and then immediately open another document, say using…
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98
3
votes
1 answer

NSWindowController/NSDocument lifecycle (closing)

I have a 'standard' OS X document based app using NSWindowController, NSDocument etc. It has an NSTextView as part of its UI. Question I have (and it's driving me nuts) is how best to trap 'Close Document' and then tell the NSTexView to finish edit.…
Scotty
  • 2,019
  • 1
  • 20
  • 31
3
votes
1 answer

Cocoa document based app, NSWindowController subclass as "main window"

I have a Cocoa document based app. I want the "main window" to be managed by my subclass of NSWindowController. I have created the subclass and laid out its interface in a .xib file with the same name. I ultimately want the same behaviour as if the…
user3956212
  • 359
  • 2
  • 14
3
votes
1 answer

Let the user choose what type of document to open

I'm creating an NSDocument application, with two document types: Website and Web Service. This is in my Info.plist: CFBundleDocumentTypes CFBundleTypeName Website
user142019
3
votes
1 answer

Shutting down multithreaded NSDocument

I have an NSDocument-based Cocoa app and I have a couple of secondary threads that I need to terminate gracefully (wait for them to run through the current loop) when the users closes the document window or when the application quits. I'm using…
toastie
  • 1,934
  • 3
  • 22
  • 35
3
votes
3 answers

Programmatically resolve NSDocument iCloud version conflicts?

I have a Mac "Shoebox" app that internally uses NSDocument objects, but does not expose the concept of individual documents to the user. (I rely on NSDocument to make syncing via iCloud easier.) My problem is that when a version conflict arises, my…
Mark
  • 6,647
  • 1
  • 45
  • 88
3
votes
1 answer

Cocoa application hides on deactivate

If i switch my NSDocument based app to another app, or switch the space, my app hides... Cannot figure out what causes this behavior... Note that Hides on deactivate is set to NO in the main window
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
3
votes
1 answer

Tell NSDocument that the document has been modified

I'm writing a Document-Based App in OSX. I found when I change the contents of the doc, the app doesn't know the document has been changed. I can close the doc without warning, which causes my unsaved content to be lost. How can I tell NSDocument…
kilik52
  • 664
  • 1
  • 6
  • 13
3
votes
1 answer

How to associate an action to a keyboard shortcut?

I've an IBAction that calls up a panel. I want to invoke that action with a keyboard shortcut but I'm at a loss on how to do it. I guess one way of doing it would be to create a menu item, associate the action to the item and then assign the…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
3
votes
0 answers

Cocoa: in a document-based application, where does one store prefs for each document?

When making a document-based application, each document could have settings associated with it: sort order, split view size, window size, font size, etc. Some of these I can see getting wrapped in with window restoration, but others seem awkward…
SG1
  • 2,871
  • 1
  • 29
  • 41
3
votes
2 answers

ios - delete single files that are downloaded into the documents directory

Firstly = I apologize because I have already tried to ask this once before here I am really struggling with this: // Override to support editing the table view. - (void)tableView:(UITableView *)tableView…
jwknz
  • 6,598
  • 16
  • 72
  • 115
3
votes
2 answers

How to set save notification when click close in document based application

I am doing a simple document based application. I've implemented readFromData and dataOfType function. Creating a newDocument and saveDocument are working. However, the question is how to set up save notification when user clicks Close. I add some…