NSDocument 子类是否是模型对象?

Is NSDocument subclass a model object or not?

我正在为 macOS Swift 编写一个多文档应用程序。我从 Xcode 提供的文档应用模板开始。目前还不清楚它是否是一个对象模型。 NSDocument是模型还是其中包含的数据是模型?

苹果says一个“文档的数据叫做数据模型”:

In the Cocoa document architecture, your document is represented by a custom subclass of NSDocument. The NSDocument class provides most of the behavior for managing your document. In your subclass, you override or fine-tune this behavior by providing custom code for reading and writing document data. A document’s data is called the data model. Each NSDocument has its own NSWindowController, which in turn creates an NSWindow object for displaying the document content.

Because a document-based app handles multiple documents that are open at the same time, it uses NSDocumentController to manage them. Cocoa provides most of the infrastructure for managing your documents. With file coordination, version management, and conflict resolution among other documents, it provides the easiest path to using iCloud.

这个NSDocument子类引入了Cocoa并且与UI层代码纠缠不清,所以很难调用一个真正的模型对象(虽然它是一个有用的抽象)。我们中的许多人都努力让真正的“模型”对象不受 UI/OS 依赖。

简而言之,NSDocument 管理的数据更恰当地被认为是“模型”。