I have a class, where most of the logic is handled for clicks and such. There, I made a function that calls another function in a different class. I want to tie this function with NSAlert's button click. However, when I click, I get the error: unrecognized selector sent to instance 0x6000001c50a0. I also have a check if an alert is open and all alerts go through a similar way.
Here's my code:
func goBack()
{
//goback code
}
func showAlert(){
if (!OtherClass.alertCheck)
{
OtherClass.alertCheck = true;
DispatchQueue.main.async(){
var alert = NSAlert()
alert.messageText = "If you want to go back, click back."
var btn = alert.addButton("back")
btn.action = #selector(OtherClass.goBack)
alert.runModal()
OtherClass.alertCheck = false
}
}
}
Even if I don't go through the dispatchQueue, the action is not triggered. I would like to know why in both cases, it doesn't work.