---
title: "dataTask(with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsession/datatask(with:)-10dy7"
---

# dataTask(with:)

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

## Declaration

```swift
func dataTask(with url: URL) -> URLSessionDataTask
```

## Parameters

- `url`: The URL to be retrieved.

## Mentioned in

Fetching website data into memory

## Return Value

Return Value The new session data task.

## Discussion

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.

## See Also

### Adding data tasks to a session

- [dataTask(with:completionHandler:)](foundation/urlsession/datatask(with:completionhandler:)-52wk8.md)
- [dataTask(with:)](foundation/urlsession/datatask(with:)-7jpys.md)
- [dataTask(with:completionHandler:)](foundation/urlsession/datatask(with:completionhandler:)-e6xv.md)
- [URLSessionDataTask](foundation/urlsessiondatatask.md)
- [URLSessionDataDelegate](foundation/urlsessiondatadelegate.md)
