Instance Method

dataTask(with:)

Creates a task that retrieves the contents of the specified URL.

Declaration

func dataTask(with url: URL) -> URLSessionDataTask

Parameters

url

The URL to be retrieved.

Return Value

The new session data task.

Discussion

After you create the task, you must start it by calling its resume() method. The task calls methods on the session’s delegate to provide you with the response metadata, response data, and so on.