Luke Patterson Luke Patterson - 4 months ago 2399x
iOS Question

Swift 2.2 Selector with multiple arguments - actually passing in

I want to use a selector, but I need to pass in the arguments
I understand the syntax follows:


but i need to actually pass in parameters. How do I do this?

Here's my attempt:

exploreTap = UITapGestureRecognizer(target: self, action: #selector(MainViewController.showViewWithIdentifier(_:exploreView,id:"explore")))


You cannot pass parameters to selectors, selector is just a method name, nothing else. You are not calling the method so you cannot pass parameters. Just call the necessary code inside your tap handler.

func onTap() {
   MainViewController.showViewWithIdentifier(exploreView, id:"explore")

and then

UITapGestureRecognizer(target: self, action: #selector(onTap))