selectorの書き方でしたら、同様の質問見つけましたので参考になれば。
NSButton storyboardを使わずにアクション
この質問者さんはviewDidLoad内で変数を再宣言しちゃっててつまづいていますが...
念のため上記リンクの回答欄のコード抜粋しておきます。
import Cocoa
class ViewController: NSViewController {
let button = NSButton()
var label = NSTextField()
let combo = NSComboBox()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = NSTextField(frame: NSRect(x: 20, y: 20, width: 150, height: 50))
label.stringValue = "実行結果"
label.backgroundColor = NSColor.green
view.addSubview(label)
// コンボボックス
let num = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]
let combo = NSComboBox(frame: NSRect(x: 60, y: 745, width: 50, height: 26))
combo.intValue = 0
for combo0 in num {
combo.addItem(withObjectValue: Int(combo0))
}
view.addSubview(combo)
let button = NSButton()
button.target = self
button.action = #selector(buttonDidClick)
button.frame = NSRect(x:200, y: 200, width: 100, height: 50)
button.title = "計算"
view.addSubview(button)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
@objc private func buttonDidClick(_ sender: Any) {
label.intValue = combo.intValue
}
}