---
title: closeCode
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/urlsessionwebsockettask/closecode-swift.property
---

# closeCode

A code that indicates the reason a connection closed.

## Declaration

```swift
var closeCode: URLSessionWebSocketTask.CloseCode { get }
```

## Discussion

Discussion You can retrieve the close code 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)
- [URLSessionWebSocketTask.CloseCode](foundation/urlsessionwebsockettask/closecode-swift.enum.md)
- [closeReason](foundation/urlsessionwebsockettask/closereason.md)
