<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/UndoManager/setActionUserInfoValue(_:forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUndoManager(im)setActionUserInfoValue:forKey:"
  },
  "title" : "setActionUserInfoValue(_:forKey:)"
}
-->

# setActionUserInfoValue(_:forKey:)

Sets a user info value for an undo or redo action.

```
func setActionUserInfoValue(_ info: Any?, forKey key: UndoManager.UserInfoKey)
```

## Parameters

`info`

The value to save in the action’s user info.

`key`

The key to associate with the user info value.

## Discussion

Set user info on an undo action to provide custom information to the action beyond its action name. You can use this for things like an icon to represent the undoable action, or a timestamp of when the undo manager registers the action.

Start by extending [`UndoManager.UserInfoKey`](/documentation/Foundation/UndoManager/UserInfoKey) with key names to identify the user info values you want to associate with undo actions.

```swift
extension UndoManager.UserInfoKey {
    static let icon: UndoManager.UserInfoKey = "icon"
}
```

Then set the user info value with this key as part of registering the undoable action. In this example, an app’s `insertLayer()` method provides a custom icon before setting up an undo action that calls the app’s `removeLayer()` method:

```swift
func insertLayer() {
    self.undoManager.setActionName("Insert layer")
    self.undoManager.setActionUserInfoValue(Image(named: "new_layer"), forKey: .icon)

    self.layers.append(Layer())

    self.undoManager.registerUndo(withTarget: self) {
        $0.removeLayer()
    }
}
```

---

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)