<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionWebSocketTask/closeReason",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSessionWebSocketTask(py)closeReason"
  },
  "title" : "closeReason"
}
-->

# closeReason

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

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

## Discussion

The close reason provides further information about why a connection closed, beyond that provided by the [`closeCode`](/documentation/Foundation/URLSessionWebSocketTask/closeCode-swift.property). The value of this property isn’t defined by [RFC 6455](https://tools.ietf.org/html/rfc6455); 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`](/documentation/Foundation/URLSessionWebSocketTask/CloseCode-swift.enum/invalid).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)