# How do I invoke an @IBAction on an NSViewController wrapped in NSViewControllerRepresentable?

**URL:** <https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108>\
**Category:** macOS\
**Created:** [November 23, 2022, 10:43am UTC](https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108 "2022-11-23T10:43:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetforme](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jetforme/32/105324_2.png) [@jetforme](https://forums.kodeco.com/u/jetforme)\
**Post date:** [November 23, 2022, 10:43am UTC](https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108/1 "2022-11-23T10:43:54Z")

</div>

How do I invoke an `@IBAction` on an `NSViewController` subclass wrapped in `NSViewControllerRepresentable`?

I can’t see a way to specify some `.commands {}` in my `DocumentGroup` that eventually call `@IBAction` methods in my wrapped view controller.

---

<div class="post-metadata">

**Author:** ![rafad](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rafad/32/110937_2.png) [@rafad](https://forums.kodeco.com/u/rafad)\
**Post date:** [November 28, 2022, 3:24pm UTC](https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108/2 "2022-11-28T15:24:01Z")

</div>

Hello, You should go to the SwiftUI section because it seems to me that your question is more appropriate there than in OS X.  
Regards!!  
Rafael

---

<div class="post-metadata">

**Author:** ![jetforme](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jetforme/32/105324_2.png) [@jetforme](https://forums.kodeco.com/u/jetforme)\
**Post date:** [November 28, 2022, 10:11pm UTC](https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108/3 "2022-11-28T22:11:17Z")

</div>

Huh, I thought I had put it in SwiftUI. In any case, the answer turns out to be a bit of a hack (IMHO): you have to call `NSApp.sendAction` from the `Command`, and send the action to `nil`, which sends it up the `NSResponder` chain. No way I can find to target a specific instance, but that’s not too much of an issue for me. What doesn’t seem to work is the enabling/disabling of menu commands.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [May 9, 2023, 2:44am UTC](https://forums.kodeco.com/t/how-do-i-invoke-an-ibaction-on-an-nsviewcontroller-wrapped-in-nsviewcontrollerrepresentable/181108/4 "2023-05-09T02:44:40Z")

</div>

Closed on May 9, 2023, 2:44am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
