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
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
23
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
  • 34,788
  • 19
  • 120
  • 195
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
  • 24
14
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,831
  • 9
  • 76
  • 80
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,927
  • 28
  • 32
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,895
  • 8
  • 63
  • 114
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,930
  • 2
  • 18
  • 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
  • 17,317
  • 32
  • 140
  • 246
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,391
  • 24
  • 32
10
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
  • 119,096
  • 131
  • 338
  • 476
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,027
  • 14
  • 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
  • 119,096
  • 131
  • 338
  • 476
9
votes
3 answers

Overriding "Edited" in window title for NSDocument

How do I prevent a window title from displaying "Edited" for an NSDocument which is dirty? I'm managing saving and autosaving myself, using a web service, and just don't want the distraction in the title bar. I've tried overriding: NSDocument's…
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
8
votes
1 answer

Is NSDocument and CoreData a possible combination, or is NSPersistentDocument the only way?

I'm making an application which creates course timetables for people at my school. This is the rough design I had in mind for the application: I'd like my NSDocument subclass to represent an individual's timetable. The idea is that they open up a…
Chris Cooper
  • 17,276
  • 9
  • 52
  • 70
8
votes
0 answers

NSDocument: AsyncOperation I never called

Some of the time when using my Document-based mac app (Xcode 10, Swift 4.2, macOS 10.13.5), I get the following error in the console: _NSDocumentBasicAsyncOperation 0x60c000233c40 went isFinished=YES without being started by the queue it is in I…
green_knight
  • 1,319
  • 14
  • 26
1
2 3
31 32