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

Cocoa Inspector - How to Reset Window Title After Closing Last Document

My document-based cocoa app has a shared inspector window whose contents change depending on which document is active. The inspector window controller is a shared singleton, instantiated form its storyboard on demand. The document class simply…
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
0
votes
0 answers

NSDocument opens .txt file but content won't show up

So I'm currently working on a plain text editor and I'm having a problem with NSDocument. When I try to open a file (read function) the opened window textField (ViewController().textField)has no stringValue. I hope somebody is able to help, thanks…
Ezekiel
  • 91
  • 11
0
votes
1 answer

Document based application - how to open recent documents merged in one window

When my app (document based) starts I open all recent documents. All documents starts at separate windows. My goal is to open all in one window in tabs.
Maciek
  • 161
  • 3
  • 11
0
votes
1 answer

Opening documents with Cocoa

I have the following method to open documents. - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { NSString *stringData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; [editorView…
nosedive25
  • 2,477
  • 5
  • 30
  • 45
0
votes
1 answer

NSDocument writeToURL:, saving a simple html document

Im trying to implement a save feature to save an html file. Currently it returns errors when I try and save. My code is - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError { NSData *saveData =…
nosedive25
  • 2,477
  • 5
  • 30
  • 45
0
votes
0 answers

Register UTI for file extension associated with dynamic UTI

Suppose an NSDocument based application defined an exported file type without specifying a UTI for it, resulting in a dynamic UTI being set by macOS for those files. Simply declaring a UTI in the app doesn’t seem to affect newly written files, the…
user73014
  • 11
  • 5
0
votes
1 answer

Getting NSDocumentController from NSDocument

I have subclassed both NSDocumentController and NSDocument. Is there a way to get to the MyDocumentController from MyDocument? Currently I have an outlet in my AppDelegate that connects to MyDocumentController, so I can get to it that way, but was…
Trygve
  • 1,317
  • 10
  • 27
0
votes
2 answers

How to access items in the main nib from a document nib?

I'm making an NSDocument-based application in which I have an inspector window. This inspector window is part of Pwnshop.nib which is my main nib. I have another nib called 'Document.nib,' which is the document window. I want to be able to change…
user142019
0
votes
0 answers

Avoid NSDocument from reopening from Trash

Working on a NSDocument-based app, I discovered that if I delete a file (package) from the filesystem, the app will still try to reopen it—from the trash. Even if this succeeded it would be confusing. Currently I have a crude check in…
Henrik
  • 3,908
  • 27
  • 48
0
votes
0 answers

Opening a file with NSDocument-based app

I'm trying to open a file, and I'm currently implementing - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError from within the NSDocument subclass. (Documentation for above method) For some reason, typeName is…
user339946
  • 5,961
  • 9
  • 52
  • 97
0
votes
2 answers

Storing Many Images in NSDocument in Objective-C : [iOS]

I am trying to store many images in NSDocument with the name pattern like :- image 1, image 2, image 3, image 4, ..... Image count should increase with number of times a register button is tapped. And for storing this button tapped count i am using…
0
votes
0 answers

NSDocument printOperationWithSettings not showing all pages

In NSDocument subclass, have this function: override func printOperationWithSettings(printSettings: [String : AnyObject]) throws -> NSPrintOperation { let printInfo: NSPrintInfo = self.printInfo var pageSize = printInfo.paperSize …
JKaz
  • 765
  • 6
  • 18
0
votes
1 answer

iOS and OSX Document Packages cross platform

I have a iOS and OSX application which is document based and i am saving complex folder hierarchy inside the document so i change my UTI type to document package. But the problem is that according to apple Document Package is just a folder. If i…
shahid610169
  • 370
  • 2
  • 11
0
votes
0 answers

autosaving in NSPersistentDocument: two documents are using the same persistent store file

In my subclass of NSPersistentDocument, I overwrite this function: func writeToURL(absoluteURL: NSURL, ofType typeName: FileType, forSaveOperation saveOperation: NSSaveOperationType, originalContentsURL…
user965972
  • 2,489
  • 2
  • 23
  • 39
0
votes
1 answer

Retieve the document name during Save operation of document based application

I have a document based application. I have overridden dataOfType function to save the appliation. However I am unable to retrieve the application name given by user in NSSavePanel while saving. Is there a way I can get the application name. Also…
Subrat
  • 175
  • 3
  • 13