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

471 questions
72
votes
4 answers

Saving image to Documents directory and retrieving for email attachment

I having trouble figuring out NSBundle & DocumentDirectory data, I have a Camera Picture "imageView" that I'm saving to the NSDocumentDirectoy and then want to retrieve it for attaching to an email, Here the saving code: - (IBAction)saveImage { …
Michael Robinson
  • 1,439
  • 2
  • 16
  • 23
22
votes
6 answers

How to inspect the responder chain?

I'm doing some crazy multiple documents inside a single window stuff with the document-based architecture and I'm 95% done. I have this two-tier document architecture, where a parent document opens and configures the window, providing a list of…
d11wtq
  • 33,252
  • 14
  • 115
  • 186
21
votes
3 answers

Clear UIWebView cache when use local image file

I use a UIWebView to load a local html, and there is a PNG file inside the html created by Objc. After the PNG file has been modified, I reload the html in UIWebView, but the image doesn't change. However, if I quit the app and reopen it, the image…
yellow
  • 702
  • 1
  • 10
  • 23
13
votes
4 answers

Support NSDocument changes in an external editor?

I have an NSDocument with some simple code: - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { self.string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; return YES; } If I change…
Sam Soffes
  • 14,138
  • 9
  • 68
  • 78
13
votes
3 answers

NSFileWrapper, lazy loading and saving

I have an NSDocument based application that uses filewrappers to save and load its data. The document can have all kinds of resources, so I don't want to load everything into memory. I might be doing something fundamentally wrong, but as soon as I…
Bob Vork
  • 2,879
  • 23
  • 31
13
votes
2 answers

Document-based app doesn't restore documents with non-file URLs

I have an application based on NSDocument with an NSDocumentController subclass. My NSDocument works with both file URLs and URLs with a custom scheme which use a web service. I handle much of the loading and saving using custom code, including…
paulmelnikow
  • 16,036
  • 6
  • 56
  • 110
11
votes
4 answers

NSDocumentController currentDocument returning nil

I'm working on my first Mac document-based application. I have subclassed NSDocument, reimplementing methods such as - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError; - (BOOL)writeToURL:(NSURL…
msoler
  • 2,810
  • 2
  • 16
  • 30
11
votes
6 answers

iCloud enabled - Stop the open file displaying on application launch?

I've just added iCloud support to an app that I am working on. Its working great, except that when I open the application without a document in focus the iCloud open file dialog appears and I don't want it to! In my app delegate I have: - (BOOL)…
Kyle
  • 16,103
  • 26
  • 123
  • 231
11
votes
1 answer

Lost with Window resume feature, autosave in user preferences and save in model for NSDocument

I started a little document based application with a NSOutlineView on the main window. I saved my model in files using NSCoding protocol in the model classes and everything is fine. Next I wanted to save the user interface (window size and position,…
Johnmph
  • 3,337
  • 21
  • 31
9
votes
1 answer

NSDocument to hold a complete folder?

I ask sorry if this argument has already been covered, but after some research i found nothing precise. I need to make a document based application, where the document is actually not a single file but a structured collection of files, in a…
hariseldon78
  • 1,000
  • 13
  • 22
9
votes
2 answers

NSFileWrapper returns nil, sometimes

I'm using NSFileWrapper for my package document. Sometimes, when I request the data of a file inside the package I get nil. This is how I query the data of a file inside the package: - (NSData*) dataOfFile(NSString*)filename { NSFileWrapper…
hpique
  • 112,774
  • 126
  • 328
  • 461
9
votes
1 answer

Using NSFileWrapper in NSDocument made of various files

I'm making a document-based Cocoa app in which the document is dynamic a collection of files (users can add or remove files). In particular, the Save and Open operations should be as fast as possible. If I understand the documentation correctly, I…
hpique
  • 112,774
  • 126
  • 328
  • 461
8
votes
2 answers

Where do you put cleanup code for NSDocument sub-classes?

I have a document-based application and I have sub-classed NSDocument and provided the required methods, but my document needs some extensive clean-up (needs to run external tasks etc). Where is the best place to put this? I have tried a few…
dreamlax
  • 89,489
  • 28
  • 156
  • 207
8
votes
2 answers

NSDocument custom icon not displaying in Finder but displaying in Quick Look

I'm designing a custom application and I've set a custom icon for my file type. I've put the icon on both Document Types and Exported UTIs section (filling in other values too, obviously). Here is what I get when I run: No icon is defined in…
Can Poyrazoğlu
  • 29,145
  • 40
  • 152
  • 327
8
votes
2 answers

How do I initialise a new NSDocument instance in Swift?

Apple documentation suggests to override an NSDocument convenience init (initWithType:error:) as described here. However, as this is a convenience init, I cannot override it. But I still need to execute some code when a new document is created. I do…
Wizard of Kneup
  • 1,265
  • 12
  • 28
1
2 3
31 32