<!--
{
  "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 -"
  ],
  "documentType" : "symbol",
  "framework" : "USDKit",
  "identifier" : "/documentation/USDKit/USDPrim/VariantSet/withEditTarget(layer:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "USDKit"
    ],
    "preciseIdentifier" : "s:6USDKit7USDPrimV10VariantSetV14withEditTarget5layer_xAA8USDLayerVSg_xAA8USDStageV0fG0VKXEtKlF"
  },
  "title" : "withEditTarget(layer:_:)"
}
-->

# withEditTarget(layer:_:)

Performs the closure with the stage’s edit target set to author
into the currently selected variant.

```
func withEditTarget<R>(layer: USDLayer? = nil, _ body: (USDStage.EditTarget) throws -> R) rethrows -> R
```

## Parameters

`layer`

The layer to target, or `nil` for the current edit target’s layer.

`body`

A closure that performs edits within the variant.

## Return Value

The value returned by `body`.

## Discussion

The previous edit target is restored when the closure returns.

> Throws: Errors from `body` are rethrown.

---

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)