<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UniqueArray/edit(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11UniqueArrayVsRi_zrlE4edityqd_0_qd_0_s10OutputSpanVyxGzqd__YKXEqd__YKs5ErrorRd__Ri_d_0_r0_lF"
  },
  "title" : "edit(_:)"
}
-->

# edit(_:)

Arbitrarily edit the storage underlying this array by invoking a
user-supplied closure with a mutable `OutputSpan` view over it.
This method calls its function argument at most once, allowing it to
arbitrarily modify the contents of the output span it is given.
The argument is free to add, remove or reorder any items; however,
it is not allowed to replace the span or change its capacity.

```
mutating func edit<E, R>(_ body: @_lifetime(0: copy 0) (inout OutputSpan<Element>) throws(E) -> R) throws(E) -> R where E : Error, R : ~Copyable
```

## Parameters

`body`

A function that edits the contents of this array through
an `OutputSpan` argument. This method invokes this function
at most once.

## Return Value

This method returns the result of its function argument.

## Discussion

When the function argument finishes (whether by returning or throwing an
error) the rigid array instance is updated to match the final contents of
the output span.

> Complexity: Adds O(1) overhead to the complexity of the function
> argument.

---

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)