---
title: "getTasksWithCompletionHandler(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsession/gettaskswithcompletionhandler(_:)"
---

# getTasksWithCompletionHandler(_:)

Asynchronously calls a completion callback with all data, upload, and download tasks in a session.

## Declaration

```swift
func getTasksWithCompletionHandler(_ completionHandler: @escaping @Sendable ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask]) -> Void)
```

```swift
var tasks: ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask]) { get async }
```

## Parameters

- `completionHandler`: The completion handler to call with the list of tasks. This handler is executed on the delegate queue.

## Discussion

Discussion The arrays passed to the completion handler contain any tasks that you have created within the session, not including any tasks that have been invalidated after completing, failing, or being cancelled.

## See Also

### Managing the session

- [finishTasksAndInvalidate()](foundation/urlsession/finishtasksandinvalidate().md)
- [flush(completionHandler:)](foundation/urlsession/flush(completionhandler:).md)
- [getAllTasks(completionHandler:)](foundation/urlsession/getalltasks(completionhandler:).md)
- [invalidateAndCancel()](foundation/urlsession/invalidateandcancel().md)
- [reset(completionHandler:)](foundation/urlsession/reset(completionhandler:).md)
- [sessionDescription](foundation/urlsession/sessiondescription.md)
