<!--
{
  "availability" : [
    "iOS: 12.2.0 -",
    "iPadOS: 12.2.0 -",
    "macCatalyst: 12.2.0 -",
    "macOS: 10.14.4 -",
    "tvOS: 12.2.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/OutputRawSpan",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s13OutputRawSpanV"
  },
  "title" : "OutputRawSpan"
}
-->

# OutputRawSpan

`OutputRawSpan` is a reference to a contiguous region of memory which starts
with some number of initialized bytes, followed by uninitialized memory.
It provides operations to access the bytes it stores,
as well as to append and to remove bytes.

```
@frozen struct OutputRawSpan
```

## Topics

### Initializers

[`init()`](/documentation/Swift/OutputRawSpan/init())

Create an OutputRawSpan with zero capacity.

[`init(buffer: UnsafeMutableRawBufferPointer, initializedCount: Int)`](/documentation/Swift/OutputRawSpan/init(buffer:initializedCount:)-1vcj6)

Unsafely create an OutputRawSpan over partly-initialized memory.

[`init(buffer: borrowing Slice<UnsafeMutableRawBufferPointer>, initializedCount: Int)`](/documentation/Swift/OutputRawSpan/init(buffer:initializedCount:)-5sduz)

Unsafely create an OutputRawSpan over partly-initialized memory.

### Instance Properties

[`var byteCount: Int`](/documentation/Swift/OutputRawSpan/byteCount)

The number of initialized bytes in this span.

[`var byteOffsets: Range<Int>`](/documentation/Swift/OutputRawSpan/byteOffsets)

The indices that are valid for subscripting the span, in ascending
order.

[`var bytes: RawSpan`](/documentation/Swift/OutputRawSpan/bytes)

Borrow the underlying initialized memory for read-only access.

[`let capacity: Int`](/documentation/Swift/OutputRawSpan/capacity)

The total number of bytes that this output span can contain.

[`var freeCapacity: Int`](/documentation/Swift/OutputRawSpan/freeCapacity)

The number of additional bytes that can be appended to this span.

[`var isEmpty: Bool`](/documentation/Swift/OutputRawSpan/isEmpty)

A Boolean value indicating whether the span is empty.

[`var isFull: Bool`](/documentation/Swift/OutputRawSpan/isFull)

A Boolean value indicating whether the span is full.

[`var mutableBytes: MutableRawSpan`](/documentation/Swift/OutputRawSpan/mutableBytes)

Exclusively borrow the underlying initialized memory for mutation.

### Instance Methods

[`func append(UInt8)`](/documentation/Swift/OutputRawSpan/append(_:))

Append a single byte to this span.

[`func append<T>(T, as: T.Type)`](/documentation/Swift/OutputRawSpan/append(_:as:)-63w17)

Appends the given value’s bytes to this span’s bytes.

[`func append<T>(T, as: T.Type)`](/documentation/Swift/OutputRawSpan/append(_:as:)-89j87)

Appends the given value’s bytes to this span’s bytes.

[`func append<T>(T, as: T.Type, ByteOrder)`](/documentation/Swift/OutputRawSpan/append(_:as:_:))

Appends the given value’s bytes to this span’s bytes.

[`func append<T>(repeating: T, count: Int, as: T.Type)`](/documentation/Swift/OutputRawSpan/append(repeating:count:as:)-1h8m1)

Appends the given value’s bytes repeatedly to this span’s bytes.

[`func append<T>(repeating: T, count: Int, as: T.Type)`](/documentation/Swift/OutputRawSpan/append(repeating:count:as:)-3z0bf)

Appends the given value’s bytes repeatedly to this span’s bytes.

[`func append<T>(repeating: T, count: Int, as: T.Type, ByteOrder)`](/documentation/Swift/OutputRawSpan/append(repeating:count:as:_:))

Appends the given value’s bytes repeatedly to this span’s bytes.

[`func finalize(for: Slice<UnsafeMutableRawBufferPointer>) -> Int`](/documentation/Swift/OutputRawSpan/finalize(for:)-4su35)

Consume the output span and return the number of initialized bytes.

[`func finalize(for: UnsafeMutableRawBufferPointer) -> Int`](/documentation/Swift/OutputRawSpan/finalize(for:)-8oz61)

Consume the output span and return the number of initialized bytes.

[`func removeAll()`](/documentation/Swift/OutputRawSpan/removeAll())

Remove all this span’s bytes and return its memory
to the uninitialized state.

[`func removeLast() -> UInt8`](/documentation/Swift/OutputRawSpan/removeLast())

Remove the last byte from this span.

[`func removeLast(Int)`](/documentation/Swift/OutputRawSpan/removeLast(_:))

Remove the last n bytes from this span, returning the memory
they occupy to the uninitialized state.

[`func withUnsafeMutableBytes<E, R>((UnsafeMutableRawBufferPointer, inout Int) throws(E) -> R) throws(E) -> R`](/documentation/Swift/OutputRawSpan/withUnsafeMutableBytes(_:))

Call the given closure with the unsafe buffer pointer addressed by this
OutputRawSpan and a mutable reference to its count of initialized bytes.

### Subscripts

[`subscript(Int) -> UInt8`](/documentation/Swift/OutputRawSpan/subscript(_:))

Accesses the byte at the specified offset in the span.

[`subscript(unchecked _: Int) -> UInt8`](/documentation/Swift/OutputRawSpan/subscript(unchecked:))

Accesses the byte at the specified offset in the span.

### Default Implementations

[Iterable Implementations](/documentation/Swift/OutputRawSpan/Iterable-Implementations)

## Relationships

### Conforms To

[`ContiguousBytes`](/documentation/Foundation/ContiguousBytes)

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

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

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

---

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)