---
title: "withEditTarget(layer:_:)"
framework: usdkit
role: symbol
role_heading: Instance Method
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+]
path: "usdkit/usdprim/variantset/withedittarget(layer:_:)"
---

# withEditTarget(layer:_:)

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

## Declaration

```swift
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

Return Value The value returned by body.

## Discussion

Discussion The previous edit target is restored when the closure returns. note: Errors from body are rethrown.
