Contents

undoActionUserInfoValue(forKey:)

Retrieves the undo action’s user info value for the given key.

Declaration

func undoActionUserInfoValue(forKey key: UndoManager.UserInfoKey) -> Any?

Parameters

  • key:

    The key associated with the value to return.

Return Value

The value that you previously registered to this key with setActionUserInfoValue(_:forKey:), or nil if the key is absent.

Discussion

Use this method to retrieve a user info value for the undo action you previously set with setActionUserInfoValue(_:forKey:).

In this example, an app’s undoButton() method provides a SwiftUI view that incorporates a previously assigned icon for the undo action:

func undoButton() -> some SwiftUI.View {
    Button(action: {
        self.undoManager.undo()
    }) {
        Label(self.undoManager.undoActionName,
              image: self.undoManager.undoActionUserInfoValue(forKey: .icon) as? Image)
    }
}

See Also

Working with user info