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

relinquishPresentedItem(toWriter:)

Notifies your object that another object or process wants to write to the presented file or directory. 別のオブジェクトまたはプロセスがその提示されたファイルまたはディレクトリに書き込みを望むことを、あなたのオブジェクトに通知します。

Declaration 宣言

optional func relinquishPresentedItem(toWriter writer: @escaping ((() -> Void)?) -> Void)

Parameters パラメータ

writer

A Block object that takes another block as a parameter and returns no value. The reacquirer block is one you pass to the writer block so that your object can be notified when the writer is done. If your object does not need to be notified, it can pass nil for the reacquirer block. あるBlockオブジェクト、それは別のブロックをパラメータとして取ります、そして値を返しません。reacquirerブロックは、あなたがwriterブロックに渡すものです、それであなたのオブジェクトはwriterが終わる時に通知されることができます。あなたのオブジェクトが通知される必要がないならば、それはnilreacquirerブロックに渡すことができます。

Discussion 議論

You use this method to provide an appropriate response when another object wants to write to your presented URL. For example, when this method is called, you would likely stop making changes to the file or directory. After taking any appropriate steps, you must execute the block in the writer parameter to let the waiting object know that it may now proceed with its task. If you want to be notified when the writer has completed its task, pass your own block to the writer and use that block to reacquire the file or URL for your own uses. あなたはこのメソッドを使うことで、別のオブジェクトがあなたの提示したURLに書き込みたい場合に適切な応答を提供できます。例えば、このメソッドが呼び出される場合、あなたはファイルまたはディレクトリに変更をするのを中止するでしょう。何らかの適切な措置を講じた後、あなたはwriterパラメータの中のブロックを実行することで、その待機しているオブジェクトにそれがもうそれのタスクに取りかかってよいことを知らせなければなりません。あなたが、writerがそれのタスクを完了した時に通知されたいならば、あなた独自のブロックをwriterに渡してください、そしてそのブロックを使ってファイルまたはURLをあなた自身の利用のために再獲得してください。

If the writer changes the file or directory, you do not need to incorporate those changes in your reacquirer block. Instead, implement the presentedItemDidChange() method and use it to detect when a writer actually wrote its changes to disk. writerがファイルまたはディレクトリを変更するならば、あなたはそれらの変更をあなたのreacquirerブロックに組み入れる必要はありません。代わりに、presentedItemDidChange()メソッドを実装してください、そしてwriterが実際にそれの変更をディスクに書き込んだ時にそれを使って突き止めてください。

The following listing shows a simple implementation of this method that sets a Boolean flag that the file being monitored is not writable at the moment. After setting the flag, it executes the writer block and passes in yet another block for the writer to execute when it is done. 以下のコード出力は、このメソッドの単純な実装を示します、それはあるブールのフラグを、その監視されているファイルが今のところ書き込み可能でないと設定します。そのフラグを設定した後、それはwriterブロックを実行します、そしてそれが終わった時にwriterが実行するさらに別のブロックを渡します。


- (void)relinquishPresentedItemToWriter:(void (^)(void (^reacquirer)(void))) writer
{
    // Prepare for another object to write to the file.
   self.fileIsWritable = NO;
 
   // Now let the writer know that it can have the file.
   // But pass a reacquisition block so that this object
   // can update itself when the writer is done.
   writer(^{
      self.fileIsWritable = YES;
   });
}

Your implementation of this method is executed using the queue in the presentedItemOperationQueue property. Your reacquirer block is executed on the queue associated with the writer. このメソッドのあなたの実装は、presentedItemOperationQueueプロパティの中のキューを使って実行されます。あなたのreacquirer(再取得)ブロックは、writerと結びつけられるキュー上で実行されます。

See Also 参照

Relinquishing Managed Files 管理するファイルを手放す

Related Documentation 関連文書