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

writeToURL:atomically:encoding:error:

Writes the contents of the receiver to the URL specified by url using the specified encoding. レシーバの内容をurlによって指定されたURLへ指定された符号化を使って書き込みます。

Declaration 宣言

- (BOOL)writeToURL:(NSURL *)url 
        atomically:(BOOL)useAuxiliaryFile 
          encoding:(NSStringEncoding)enc 
             error:(NSError * _Nullable *)error;

Parameters パラメータ

url

The URL to which to write the receiver. Only file URLs are supported. このURLに対してレシーバを書き出します。ファイルURLだけがサポートされます。

useAuxiliaryFile

If YES, the receiver is written to an auxiliary file, and then the auxiliary file is renamed to url. If NO, the receiver is written directly to url. The YES option guarantees that url, if it exists at all, won’t be corrupted even if the system should crash during writing. YESならば、レシーバは補助ファイルに書き出されます、それから補助ファイルはurlに改名されます。NOならば、レシーバは直接にurlへと書き出されます。YESオプションはurlを保証します、それがともかく存在するならば、システムが書き出しの間にクラッシュするとしても。

The useAuxiliaryFile parameter is ignored if url is not of a type that can be accessed atomically. useAuxiliaryFileパラメータは無視されます、もしurlが原子的にアクセスされることができる型のものでないならば。

enc

The encoding to use for the output. 出力のために使われる符号化。

error

If there is an error, upon return contains an NSError object that describes the problem. If you are not interested in details of errors, you may pass in NULL. エラーがあるならば、戻りでは、問題を記述するNSErrorオブジェクトを含みます。あなたがエラーの詳細に興味がないならば、あなたはNULLを渡すかもしれません。

Return Value 戻り値

YES if the URL is written successfully, otherwise NO (if there was a problem writing to the URL or with the encoding). YES、もしそのURLがうまく書き込まれるならば、そうでなければNO(URLへの書き込みまたは符号化で問題があった場合)。

Discussion 議論

This method stores the specified encoding with the file in an extended attribute under the name com.apple.TextEncoding. The value contains the IANA name for the encoding and the CFStringEncoding value for the encoding, separated by a semicolon. The CFStringEncoding value is written as an ASCII string containing an unsigned 32-bit decimal integer and is not terminated by a null character. One or both of these values may be missing. Examples of the value written include the following: このメソッドは、指定された符号化をファイルに供給します、拡張された属性で、名前com.apple.TextEncodingのもとで。値は、符号化に対するIANA名と符号化に対するCFStringEncoding値を含みます、セミコロンで隔てられます。CFStringEncoding値は、符号なし32ビット10進整数を含んでいるASCII文字列として書き込まれます、そしてヌル文字で終端されません。これらの値の1つまたは両方は、欠けているかもしれません。書き出される値の例は以下を含みます:

  • MACINTOSH;0

  • UTF-8;134217984

  • UTF-8;

  • ;3071

The methods initWithContentsOfFile:usedEncoding:error:, initWithContentsOfURL:usedEncoding:error:, stringWithContentsOfFile:usedEncoding:error:, and stringWithContentsOfURL:usedEncoding:error: use this information to open the file using the right encoding. メソッドinitWithContentsOfFile:usedEncoding:error:initWithContentsOfURL:usedEncoding:error:stringWithContentsOfFile:usedEncoding:error:、そしてstringWithContentsOfURL:usedEncoding:error:は、この情報を使うことでファイルを正しい情報を使って開きます。

See Also 参照

Writing to a File or URL ファイルまたはURLに書き込む