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

Custom accessory view for NSSavePanel of NSDocument

Consider a Cocoa NSDocument that supports two document types (e.g. BMP and JPEG). While one type has no save options (e.g. BMP), the other does (e.g. compression level for JPEG). How do you implement this? I understand that you should override…
hpique
  • 119,096
  • 131
  • 338
  • 476
6
votes
2 answers

Export NSDocument in Mac app

How do you export a NSDocument in one format into another NSDocument in another format? I would like to implement the typical Export option in my document-based app. I'm not sure where I should put the format conversion code, and what is already…
hpique
  • 119,096
  • 131
  • 338
  • 476
6
votes
4 answers

Open any folder with NSDocument

I am trying to write an application that can open any folder in the NSDocument subclass but can't figure out the right Info.plist settings. It is important that my app should not use bundles, neither folders with a particular file extensions, just…
MrTJ
  • 13,064
  • 4
  • 41
  • 63
5
votes
2 answers

Suggested save name of an untitled NSDocument

Is there a way to suggest a file name for the initial save dialog (of an untitled document) to use for a document in the nsdocument framework?
Duncan
  • 443
  • 1
  • 5
  • 12
5
votes
3 answers

Can I write to the resource fork using NSDocument?

I'd like to store some additional information along with a document, but I can't use bundles or packages, and I cannot store it inside the document itself. The application is a text editor, and I'd like it to store code folding and bookmark…
user142019
5
votes
2 answers

Enable Automatic Lightweight Migration of Core Data on NSPersistentDocument

ALM is great. But I can't get it to work on a project that uses Core Data with NSDocument. It seems that ALM is disabled by default. Fine. For any normal project, you'd add the two appropriate options to the dictionary in this line: if…
Adam
  • 32,900
  • 16
  • 126
  • 153
5
votes
1 answer

Adding an accessory view to an NSDocument's save panel in addition to its own file type popup button

I have an NSDocument based application that can save to multiple file types, so when saving a document, NSDocument helpfully adds a pop-up button to the save panel as its accessory view that lets the user choose what type they'd like to save as.…
Brian Webster
  • 11,915
  • 4
  • 44
  • 58
5
votes
1 answer

Cocoa: How to re-read file content after file has been changed from another app using NSDocument?

I have a document based cocoa app that opens an .md file to display the markdown content in a nice format. If I change the .md file in another app like textedit, I want to reload the views in my app. Here's what I have working so far: import…
Jamis Charles
  • 5,827
  • 8
  • 32
  • 42
5
votes
2 answers

How to read data from NSDocumentDirectory

Hi everyone I am working on an application which records the user sound and save that to NSDocumentDirectory.The data files are saving well.But the problem is that i want to play those files.I am using the table view for this to populate it with the…
Sabby
  • 2,586
  • 2
  • 27
  • 41
5
votes
1 answer

Looking to introduce tabs to document-based application, ideas?

I have a document based application, that so far simply edits documents with a new window for each document. I'm now adding the ability to create a project, which is a document in itself. That project will contain a list of files that can be edited…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
5
votes
2 answers

Cocoa NSDocument: getting autosave to work

Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc controller should do it, but after calling [[NSDocumentController sharedDocumentController] setAutosavingDelay:2.0]; in my controller, autosave doesn't…
taco
  • 829
  • 1
  • 9
  • 17
5
votes
1 answer

Overwriting NSDocument's init(contentsOf:ofType:) in Swift

background: Regarding to the document-based Cocoa application, Apple suggests to override NSDocument's init(contentsOf:ofType:) to customize things, therefore it seems as if it's a good place to override. You can override this method to customize…
1024jp
  • 2,058
  • 1
  • 16
  • 25
5
votes
1 answer

How do you bind a storyboard view to a Core Data entity when using NSDocument?

I'm building an OS X app that uses core data, NSDocument, storyboards, and Cocoa bindings. My expectation is that the following occurs: An instance of MyDocument (NSDocument subclass) is created. MyDocument creates a Core Data…
Bob Whiteman
  • 2,481
  • 2
  • 23
  • 27
5
votes
2 answers

Set representedObject on an NSViewController in a document-based OS X application

I am working on a simple OS X Cocoa application, in which the user fills in a form and the application performs some calculations that pop up in other fields. I started with the default Document-Based Application template on Xcode 6.3.2 (for…
wolfteeth
  • 86
  • 1
  • 8
5
votes
1 answer

How to check if an NSDocument has unsaved changes?

I know how to tell NSDocument that there are new changes, with -(void)updateChangeCount:. But, I can't find a method changeCount or something like this to check if an NSDocument has unsaved changes. Is there a way to check that?
Colas
  • 3,473
  • 4
  • 29
  • 68
1 2
3
31 32