Instance Method インスタンスメソッド

initWithFilePresenter:

Initializes and returns a file coordinator object using the specified file presenter. ファイルコーデネータオブジェクトをこの指定されたファイルプレゼンタを使って初期化して返します。

Declaration 宣言

- (instancetype)initWithFilePresenter:(id<NSFilePresenter>)filePresenterOrNil;

Parameters パラメータ

filePresenterOrNil

The file presenter object that is initiating some action on its file or directory. This object is assumed to be performing the relevant file or directory operations and therefore does not receive notifications about those operations from the returned file coordinator object. This parameter may be nil. ファイルプレゼンタオブジェクト、それはある動作をそれのファイルまたはディレクトリ上で着手しています。このオブジェクトは、関連のあるファイルまたはディレクトリ演算それらを実行していると仮定されます、そしてそれゆえそれらの演算についての通知をその返されるコーディネータオブジェクトから受け取りません。このパラメータはnilであるかもしれません。

Return Value 戻り値

A file coordinator object to use to coordinate file-related operations. ファイル関連演算それらを協調させるために使うためのファイルコーディネータオブジェクト。

Discussion 議論

Specifying a file presenter at initialization time is strongly recommended, especially if the file presenter is initiating the file operation. Otherwise, the file presenter itself would receive notifications when it made changes to the file and would have to compensate for that fact. Receiving such notifications could also deadlock if the file presenter’s code and its notifications run on the same thread. ファイルプレゼンタを初期化時に指定することは強く推奨されます、特にファイルプレゼンタがファイル演算に着手しているならば。そうでなければ、ファイルプレゼンタそれ自体が、それが変更をファイルにする場合に通知を受け取るでしょう、そしてその事実に対して補填しなければならないでしょう。そのような通知を受け取ることはまた膠着状態になる可能性があります、もしファイルプレゼンタの持つコードとそれの通知が同じスレッド上で動作するならば。

Specifically, associating an NSFileCoordinator with an NSFilePresenter accomplishes the following: とりわけ、NSFileCoordinatorがNSFilePresenterと提携することは以下のことを成し遂げます:

  • Prevents the file coordinator from sending messages to the file presenter. This means that the file presenter won’t receive notifications about its own file operations. There is one exception: Messages about versions of the presented item being added, remove, or resolved during coordinated writing are sent to every relevant file presenter. ファイルコーディネータがメッセージをファイルプレゼンタに送ることを防止します。これが意味するのは、ファイルプレゼンタがそれ自身のファイル演算についての通知を受け取らないということです。例外が1つあります:協調書き込みの間に追加、除去、または解決されている現存の項目バージョンについてのメッセージは、すべての関連するファイルプレゼンタに送られます。

  • Prevents deadlocks that could occur when the file presenter performs a coordinated write operation in response to a savePresentedItemChangesWithCompletionHandler: message. Usually, coordinated writes must wait for all the coordinated read operations on the same file or directory. However, when a coordinated read forces a file presenter to write its contents, the write operation must proceed before the read operation can finish. 膠着状態を防ぎます、それはファイルプレゼンタが協調書き込み演算をsavePresentedItemChangesWithCompletionHandler:メッセージに答えて実行する場合に起こる可能性があります。通常は、協調書き込みは同じファイルまたはディレクトリ上での全ての協調読み込み演算に対して待機しなければなりません。しかしながら、協調読み込みがファイルプレゼンタにそれの内容を書き込むよう強制する場合、書き込み演算は読み出し演算が終了できる状態になる前に取りかからなければなりません。

  • Prevents race conditions that could occur when the file presenter is sent a presentedItemDidMoveToURL: message and at the same time—but before this message is dequeued—the file presenter enqueues an operation using the old URL on a different queue. For the file coordinators to work effectively, however, the coordinator must be initialized on the same operation queue that the file presenter uses to receive its messages. 競合状態を防ぎます、それはファイルプレゼンタがあるpresentedItemDidMoveToURL:メッセージを送られるそして同時に — しかしこのメッセージがデキューされる前に — ファイルプレゼンタがある演算を古いURLを使って異なるキュー上でエンキューする場合に発生する可能性があります。ファイルコーディネータそれらが効果的に働くためには、しかしながら、そのコーディネータは、ファイルプレゼンタがそれのメッセージを受け取るために使うのと同じ演算キュー上で初期化されなければなりません。

  • Allows the file coordination mechanism to gracefully handle file presenters that initially contain nil in the presentedItemURL property, but that can later contain a non-nil value after creating the item using a coordinated write operation. For example, AppKit uses this feature to instantiate new NSDocument objects immediately, instead of waiting until after the user saves the document. ファイル協調機構に美しくそれらファイルプレゼンタを取り扱わせます、それらは元々nilpresentedItemURLプロパティにおいて含みます、しかしそれは後で非nil値を含むことが、協調書き込み演算を使って項目を作成後に可能です。例えば、AppKitはこの特徴を使って、新しいNSDocumentオブジェクトを直接にインスタンス化します、ユーザが書類を保存する後まで待機する代わりにです。