---
title: "tryToPerform(_:with:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nswindow/trytoperform(_:with:)"
---

# tryToPerform(_:with:)

Dispatches action messages with a given argument.

## Declaration

```swift
func tryToPerform(_ action: Selector, with object: Any?) -> Bool
```

## Parameters

- `action`: The selector to attempt to execute.
- `object`: The message’s argument.

## Return Value

Return Value true when the window or its delegate perform action with object; otherwise, false.

## Discussion

Discussion The window tries to perform the method action using its inherited NSResponder method tryToPerform(_:with:). If the window doesn’t perform action, the delegate is given the opportunity to perform it using its inherited NSObject method perform(_:with:).

## See Also

### Handling Events

- [currentEvent](appkit/nswindow/currentevent.md)
- [nextEvent(matching:)](appkit/nswindow/nextevent(matching:).md)
- [nextEvent(matching:until:inMode:dequeue:)](appkit/nswindow/nextevent(matching:until:inmode:dequeue:).md)
- [discardEvents(matching:before:)](appkit/nswindow/discardevents(matching:before:).md)
- [postEvent(_:atStart:)](appkit/nswindow/postevent(_:atstart:).md)
- [sendEvent(_:)](appkit/nswindow/sendevent(_:).md)
