<!--
{
  "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/finalize(for:)-4su35",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s13OutputRawSpanV8finalize3forSis5SliceVySwG_tF"
  },
  "title" : "finalize(for:)"
}
-->

# finalize(for:)

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

```
consuming func finalize(for buffer: Slice<UnsafeMutableRawBufferPointer>) -> Int
```

## Parameters

`buffer`

The buffer we expect the `OutputRawSpan` to reference.
This must be the same region of memory passed to
the `OutputRawSpan` initializer.

## Return Value

The number of initialized bytes in the same buffer, as
tracked by the consumed `OutputRawSpan` instance.

## Discussion

This method should be invoked in the scope where the `OutputRawSpan` was
created, when it is time to commit the contents of the updated buffer
back into the construct being initialized.

The context that created the output span is expected to remember what
memory region the span is addressing. This consuming method expects to
receive a copy of the same buffer pointer as a (loose) proof of ownership.

---

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)