<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/tryToPerform(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindow(im)tryToPerform:with:"
  },
  "title" : "tryToPerform(_:with:)"
}
-->

# tryToPerform(_:with:)

Dispatches action messages with a given argument.

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

## Parameters

`action`

The selector to attempt to execute.

`object`

The message’s argument.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> when the window or its delegate perform `action` with `object`; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

The window tries to perform the method `action` using its inherited `NSResponder` method [`tryToPerform(_:with:)`](/documentation/AppKit/NSResponder/tryToPerform(_:with:)). If the window doesn’t perform `action`, the delegate is given the opportunity to perform it using its inherited `NSObject` method <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/perform(_:with:)>.

---

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)