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

bytes(from:delegate:)

Retrieves the contents of a given URL and delivers an asynchronous sequence of bytes.

Declaration 宣言

func bytes(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (URLSession.AsyncBytes, URLResponse)

Parameters パラメータ

url

The URL to retrieve.

delegate

A delegate that receives life cycle and authentication challenge callbacks as the transfer progresses.

Return Value 戻り値

An asynchronously-delivered tuple that contains a URLSession.AsyncBytes sequence to iterate over, and a URLResponse.

Discussion 議論

Use this method when you want to process the bytes while the transfer is underway. You can use a for-await-in loop to handle each byte. For textual data, use the URLSession.AsyncBytes properties characters, unicodeScalars, or lines to receive the content as asynchronous sequences of those types.

To wait until the session finishes transferring data and receive it in a single Data instance, use data(from:delegate:).

See Also 参照

Performing Asynchronous Transfers 非同期転送を実行する