---
title: "finalize(for:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/outputrawspan/finalize(for:)-8oz61"
---

# finalize(for:)

Consume the output span (relinquishing its control over the buffer it is addressing), and return the number of initialized bytes in it.

## Declaration

```swift
consuming func finalize(for buffer: 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

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

## Discussion

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.
