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

Testing NSDocument

I'm just getting started with unit testing and I'm wondering how to correctly test a NSDocument subclass? In my test setUp I can init the document but that doesn't reflect how the document is setup when it's used by the app, specifically the…
2
votes
2 answers

Load a saved image from documents directory

I have used the code given here to save and load images It works fine when i use it together in one view controller, but when i use the saveImage method in one view controller and try to load the image in another view controller the image returned …
Adolf Dsilva
  • 13,092
  • 8
  • 34
  • 45
2
votes
2 answers

How can I create a document-based application that cannot create a new document?

I have a document-based application that is designed to process existing documents, not to create new documents. How do I prevent the application from creating a new, blank document when launched by opening it from the Finder?
Randall
  • 725
  • 9
  • 27
2
votes
2 answers

NSDocument saveDocumentWithDelegate deadlocked during App termination

NSDocument continues to be a software maintenance nightmare. Anyone else having a problem where they want certain blocking dialogs to be handled SYNCHRONOUSLY? BEGIN EDIT: I may have found a solution that allows me to wait synchronously Can anyone…
Keith Knauber
  • 752
  • 6
  • 13
2
votes
1 answer

Why aren't the init and windowControllerDidLoadNib: method called when a autosaved document is automatically open ?

I have a NS(Persistent)Document. I run my application via Xcode, then create a new document (without any data), and then quit my application. In this case, I can check that the init and windowControllerDidLoadNib: are called If I re-run my…
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
1 answer

Binding a Menu Item to a property of the First Responder

I have a document-based application. In my document class, I have a BOOL property : isActionPossible. I also have an IBAction : - (IBAction) doTheAction:(id)sender. Now, in MainMenu.xib, I want to connect a menu item to the action. This is easy,…
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
1 answer

Does NSFileWrapper support lazy loading?

I am creating a NSDocument package that contains potentially hundreds of large files, so I don't want to read it all in when opening the document. I've spent some time searching, but I can't find a definitve answer. Most people seem to think that…
Dejal
  • 813
  • 6
  • 18
2
votes
1 answer

Proper way to close NSDocument programmatically

I have a subclass of NSDocument that crashes whenever I use [self close] to avoid the default 'save' dialog for new documents: 2013-02-25 15:23:06.338 MyApp[692:403] An uncaught exception was raised 2013-02-25 15:23:06.338 MyApp[692:403] NSWindow:…
diego
  • 120
  • 10
2
votes
1 answer

NSDocument - how to prevent a document from being marked as updated automatically?

I have a cocoa app that allows the user to enter a query. I'm using an NSWebView with a TextArea HTML object. The problem is, as soon as I type anything into the textarea, my document gets marked as updated. Does anyone know of a way to prevent…
Kyle
  • 17,317
  • 32
  • 140
  • 246
2
votes
2 answers

Show sheet for new document window

When the user creates a new document in my NSDocument-based Cocoa application, I want the new document window to show a sheet where the user can set some initial document parameters. This sheet shall not be displayed, however, when an existing…
tajmahal
  • 1,665
  • 3
  • 16
  • 29
2
votes
0 answers

How to show document preview in iCloud conflicts sheet in Mac App using NSDocument

I am creating a Mac App, using NSDocument, that stores a custom class of documents to iCloud. I was able to get the program to store documents to iCloud quite easily by just Code Signing it, Sandboxing it, and adding iCloud entitlements; however,…
2
votes
2 answers

Include iCloud on save dialog box in mac app

I have implemented the iCloud support on my Mac document-based app. NSDocument subclass can handle open e save file on local storage and iCloud. But, I can upload my files on iCloud only dragging it on the Open-New File Panel. When the app prompt…
fnovelli
  • 68
  • 4
2
votes
1 answer

Different menubar in document based apps

I've a cocoa app based on NSDocument, I've two types of document. Every document type has its own menu items, all items are defined in mainmenu.xib. As defined in Apple UI guidelines the menu items irrelevant for a doc type are shown grayed. I have…
dafi
  • 3,492
  • 2
  • 28
  • 51
2
votes
1 answer

Mac app, NSDocument window does not appear in Window menu

I have continued work on an app made by another. It looks in relevant parts identical to the standard NSDocument window-based app that you get when starting a new project (where the Window menu works like normal, ie. the NSDocument appears in the…
Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
2
votes
0 answers

NSDocument could not be opened in app with multiple document types

My app has two custom document types. Both are declared, and their UTIs exported, in the target. Both UTIs conform to public.data and public.content; and the documents both use NSKeyedArchiver for reading and writing to disk. Within the NSDocument…
stiggs
  • 303
  • 4
  • 9