I'm creating a view programatically, and adding a function so the action responds to the UIControlEvents.TouchUpInside event:
button.addTarget(self, action: action, forControlEvents:
UIControlEvents.TouchUpInside)
So, by going into the documentation I've added this action as a selector:
#selector(ViewController.onRegularClick)
XCode then complaints about:
Argument of #selector refers to a method that is not exposed to Objective-C
So I have to set up the handler function with:
@objc func onRegularClick(sender: UIButton)
Can some one please put this noob on the right direction by guiding me to the documentation, or even give a short explanation, on:
- why can't I no longer pass simply the function name String to the action?
- how is the proper way to implement this following the Swift Way? Using the Selector class?
- why do we need to pass the @objc keyword and how it affects the function?
Thank you!