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
5
votes
2 answers

Create Subfolder in NSDocumentDirectory

I just wanted to know if it's possible to create a subfolder in the NSDocumentDirectory and write data into that created folder, like: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString…
Sean
  • 333
  • 7
  • 19
5
votes
2 answers

Music convert and how to know if writing are completed

i had to convert big file size song from iTunes library to a smaller 8K song file. As i did the converting async, the bool always return true even though writing to doc folder are not completed. At the moment i'm using a delay of 10sec before i…
Desmond
  • 5,001
  • 14
  • 56
  • 115
5
votes
4 answers

Use ZIP-archives to store NSDocument data

I noticed that Apple started using zip archives to replace document packages (folders appearing as a single file in Finder) in the iWork applications. I'm considering doing the same as I keep getting support emails related to my document packages…
Markus Müller-Simhofer
  • 3,391
  • 1
  • 28
  • 32
5
votes
1 answer

NSDocument architecture pros and cons

Does anybody have any NSDocument pros and cons they'd like to share? In particular: Once you depend on the NSDocument architecture, is it difficult to refactor it out if you need to? Are there performance implications? Does it limit you in…
conmulligan
  • 7,038
  • 6
  • 33
  • 44
5
votes
0 answers

Wrapping large SQLite databases in an NSDocument bundle

I am writing an NSDocument based application that has an SQLite database that I wish to tag along in the document bundle. It consists of some number of tables, with the schema for each table being a timestamp and a value. This database will start…
4
votes
2 answers

Sharing code between NSDocument and UIDocument

I have created a document-based app that uses Core Data. I created the mac version first, and now that it's working properly, I am moving on to create an iOS version of it. I just can't get my head around how to maximize code reuse between the…
Frost
  • 638
  • 5
  • 20
4
votes
1 answer

Bug in Cocoa document-based app with the window's document icon popup menu

I have a document-based app that supports Versions and Autosave. When you click the proxy icon, a popup menu appears like in any other document app, too: You notice this weird NSMenuItem item? It's not supposed to look like that. In Quartz Composer…
Fabian Kreiser
  • 8,307
  • 1
  • 34
  • 60
4
votes
3 answers

How to Sync an NSDocument from Mac osx to iPad/iPhone with iCloud

I have seen iCloud Document sample code for iOS and I used it to sync a uidocument to and from iCloud and now I am trying to sync iCloud with an nsdocument on a Mac OSX app which doesn't have UIDocument. I tried to change UIDocument to NSDocument…
Refael.S
  • 1,634
  • 1
  • 12
  • 22
4
votes
2 answers

Is NSDocument the correct choice when most app 'documents' are not file-based?

I am writing a Mac Cocoa application that will manipulate database files, which can be easily be implemented using NSDocument technology, as they relate directly to disk files. However the majority of the app will manipulate items within this…
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
4
votes
1 answer

NSDocument based application to read/write sqlite db

I'm implementing an application for Mac OS X to easily access to SQLite databases. Since the user will be able to work on more files at the same time, I opted for a document based application. Most books and tutorials explain how to create and read…
showerapps
  • 252
  • 2
  • 10
4
votes
1 answer

applicationShouldOpenUntitledFile returns NO, but app still opens blank documents

I'm not clear on how to stop a document-based application from displaying an empty document at startup. In a previous question that I posted, someone said, "Are you sure the window delegate is being set correctly and isn't nil?" Can someone…
Paul
  • 130
  • 5
4
votes
1 answer

Cascading in custom NSWindowController

I have a document-based application. I override NSDocument's makeWindowControllers to instantiate a custom window controller. Its initializer calls init(window: NSWindow?) of its superclass, i.e. it does not use any of the initializers that involve…
mistercake
  • 692
  • 5
  • 14
4
votes
2 answers

How to tell if NSWindow is being used to browse document versions (right side of version browser UI)

The OS X document versions browser (get to it from File > Revert to > Browse All Versions) shows the current version on the left side and and stack of older versions on the right side. The window controller on the left side gets notifications…
Jesse Grosjean
  • 607
  • 4
  • 10
4
votes
1 answer

Exported UTI not being picked up by macOS

I'm trying to export a UTI in my application, but macOS (10.3.2) is not picking it up. I've replicated my issue in a smaller project. Here's the relevant part of info.plist: UTExportedTypeDeclarations
Alexander
  • 59,041
  • 12
  • 98
  • 151
4
votes
1 answer

Document Type Icon not showing on custom file MacOS

My application needs to have custom document support, but I did not start out with a Document-template in xcode. I did manage to properly load and save the data by following among other things this tutorial:…