<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 12.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/NWConnection/ContentContext",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "s:7Network12NWConnectionC14ContentContextC"
  },
  "title" : "NWConnection.ContentContext"
}
-->

# NWConnection.ContentContext

An object that represents a message to send or receive, containing protocol metadata and send properties.

```
class ContentContext
```

## Overview

For sending, you should use [`defaultMessage`](/documentation/Network/NWConnection/ContentContext/defaultMessage) unless there is a reason to override some values.

You can pass [`finalMessage`](/documentation/Network/NWConnection/ContentContext/finalMessage) to mark the final message in a connection. Once this context is used for sending, and the send is marked as complete, no more data can be sent on the connection.

If you are using a protocol that expects message content, like WebSocket or a custom framer, create a custom context and set metadata using [`protocolMetadata`](/documentation/Network/NWConnection/ContentContext/protocolMetadata).

## Topics

### Using Constant Send Contexts

[`static let defaultMessage: NWConnection.ContentContext`](/documentation/Network/NWConnection/ContentContext/defaultMessage)

A static context representing a message with default properties.

[`static let finalMessage: NWConnection.ContentContext`](/documentation/Network/NWConnection/ContentContext/finalMessage)

A static context that’s marked as the final message in a connection.

[`static let defaultStream: NWConnection.ContentContext`](/documentation/Network/NWConnection/ContentContext/defaultStream)

A static context representing the total stream of bytes on a connection.

### Creating Custom Send Contexts

[`init(identifier: String, expiration: UInt64, priority: Double, isFinal: Bool, antecedent: NWConnection.ContentContext?, metadata: [NWProtocolMetadata]?)`](/documentation/Network/NWConnection/ContentContext/init(identifier:expiration:priority:isFinal:antecedent:metadata:))

Initializes a custom message context.

[`let identifier: String`](/documentation/Network/NWConnection/ContentContext/identifier)

The identifier of the message, used for debugging.

[`var protocolMetadata: [NWProtocolMetadata]`](/documentation/Network/NWConnection/ContentContext/protocolMetadata)

An array of protocol metadata used to configure per-message or per-packet properties.

[`class NWProtocolMetadata`](/documentation/Network/NWProtocolMetadata)

The abstract superclass for specifying metadata about a network protocol.

[`let antecedent: NWConnection.ContentContext?`](/documentation/Network/NWConnection/ContentContext/antecedent)

An optional message context that must be sent before the context you are sending.

[`let expirationMilliseconds: UInt64`](/documentation/Network/NWConnection/ContentContext/expirationMilliseconds)

A number of milliseconds after which sending the data associated with this context must begin, otherwise the data is discarded.

[`let relativePriority: Double`](/documentation/Network/NWConnection/ContentContext/relativePriority)

A relative value of priority used to reorder contexts when sending.

### Inspecting Receive Contexts

[`let isFinal: Bool`](/documentation/Network/NWConnection/ContentContext/isFinal)

A Boolean indicating whether this context represents the final message being sent or received.

[`func protocolMetadata(definition: NWProtocolDefinition) -> NWProtocolMetadata?`](/documentation/Network/NWConnection/ContentContext/protocolMetadata(definition:))

Retreives the metadata associated with a specific protocol.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherited By

[`Message`](/documentation/Network/NWConnectionGroup/Message)

---

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)