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

# tryToPerform(_:with:)

Dispatches an action message to the specified target.

## Declaration

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

## Parameters

- `action`: The action message you want to dispatch.
- `object`: The target object that defines the specified selector.

## Return Value

Return Value true if either the receiver or its delegate can accept the specified selector; otherwise, false. This method also returns false if aSelector is nil.

## Discussion

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

## See Also

### Related Documentation

- [responds(to:)](objectivec/nsobjectprotocol/responds(to:).md)

### Posting actions

- [sendAction(_:to:from:)](appkit/nsapplication/sendaction(_:to:from:).md)
- [target(forAction:)](appkit/nsapplication/target(foraction:).md)
- [target(forAction:to:from:)](appkit/nsapplication/target(foraction:to:from:).md)
