---
title: closeReason
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/urlsessionwebsockettask/closereason
---

# closeReason

A block of data that provides further information about why a connection closed.

## Declaration

```swift
var closeReason: Data? { get }
```

## Discussion

Discussion The close reason provides further information about why a connection closed, beyond that provided by the closeCode. The value of this property isn’t defined by RFC 6455; the endpoints define how it’s used. You can retrieve the close reason at any time. When the task is not yet closed, this value is URLSessionWebSocketTask.CloseCode.invalid.

## See Also

### Closing the connection

- [cancel(with:reason:)](foundation/urlsessionwebsockettask/cancel(with:reason:).md)
- [closeCode](foundation/urlsessionwebsockettask/closecode-swift.property.md)
- [URLSessionWebSocketTask.CloseCode](foundation/urlsessionwebsockettask/closecode-swift.enum.md)
