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

Open sample document from bundle

I would like my OS X app to open a sample document located in the application bundle. I'm currently doing the following: NSString* path = [[NSBundle mainBundle] pathForResource:@"tutorial.doc" ofType:nil]; [_documentController…
hpique
  • 119,096
  • 131
  • 338
  • 476
0
votes
1 answer

NSDocument app and file extension

I have created a document based app that needs to open xml text files with a particular extension. When I created the project in Xcode using the NSDocument template I specified the extension I wanted and everything was working fine. Following the…
Jacopo
  • 1,031
  • 2
  • 12
  • 25
0
votes
1 answer

NSDocument isLocked implementation for 10.7?

How can I check if a document isLocked in 10.7? NSDocument has a method isLocked, but it available only on 10.8.
Yoav
  • 5,962
  • 5
  • 39
  • 61
0
votes
1 answer

Why is my dataOfType: not called when saving?

I have an NSDocument that contains a dataOfType method, but it is not called when I do a save. - (NSData *)dataOfType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { NSLog(@"db: %@", db); return…
Carelinkz
  • 936
  • 8
  • 27
0
votes
1 answer

Why do I get multiple instances of NSDocument but only one window?

In my Document based application, no less than three documents are opened when I run the app, yet only one window displays. When I save&quit, it saves another document than the one that belongs to the window. How can this happen? In particular, I do…
Carelinkz
  • 936
  • 8
  • 27
0
votes
1 answer

Can I create an Untitled NSDocument in readFromData?

I'm rewriting my app that reads and graphs data created by a physics simulation program. The original version reads the data files but doesn't save any type of document. I'd like to add the ability to write a document file that contains presentation…
SSteve
  • 10,550
  • 5
  • 46
  • 72
0
votes
1 answer

Make NSDocument "edited" when a binded control changes

I have an array of NSDictionaries and a NSDictionary iVar (*selectedDictionary) that points to one of the array's objects. *selectedDictionary points to a different object every time the user selects a different row in a NSTableView. Several GUI…
0
votes
1 answer

Best Practices For Saving NSDocument

I am working on a basic hello world application that will open a txt document, edit it and then finally save the document. What is the best practice for handling the edit. I have read Apple's documentation throughly, but when I check for the NSError…
Cory D. Wiles
  • 556
  • 1
  • 6
  • 21
0
votes
1 answer

Intercepting Save in Core Data Document

I have a window with a small text box, bound to a Core Data attribute. The value the user enters into the text box needs to be within certain parameters. These parameters are dynamic. If the entered value is outside of the parameters, a dialog box…
-1
votes
2 answers

Lion previous versions working for restore, but UI bindings not updated after performing restore

I'm working on an app currently, and was scratching my head thinking that previous versions wasn't working; however it turns out that closing the document window and re-opening after a restore the restored values are now displayed. The problem…
Clint
  • 6,133
  • 2
  • 27
  • 48
-1
votes
1 answer

Get NSDocument from NSObject

i am on macOS, objective-c, not iOS. I am currently re-writing my app to be document based. I now save the reuired data in each NSDocument file as property which works great including autosave. I can access that data from NSViewControllers…
Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
-1
votes
1 answer

Saving with NSDocument in a Second ViewController

I am trying to simply save using NSDocument to a rtf. The code works fine but when I try to save to a view controller that isn't the initial child to the window controller it throws an error from a modal saying 'The document “” could not be saved as…
Cartisim
  • 116
  • 10
-1
votes
1 answer

NSCoder "only defined abstract class" woes

I have a simple class that (once fleshed out) will constitute the data handled by an NSDocument subclass. But, I am getting stuck right out of the gate trying to save/init the class using NSDocument's data(ofType:) and read(from: ofType:)…
MikeMayer67
  • 570
  • 6
  • 17
-1
votes
1 answer

Saving High Score Data with Swift

I am trying to save a high score using Swift for my SpriteKit game. There are several good examples on StackOverflow, one of which I got to work temporarily, but could not function properly in the Swift file where all of my nodes (and actual game)…
TerranceW
  • 302
  • 2
  • 12
1 2 3
31
32