Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 4 using selector with Multiple Parameters [duplicate]

I write with Swift 4 and try to write a function that send categoryId as action but I couldn't write .I think my syntax is wrong.If I write function without parameters its not a problem but I get error with parameters functions. Could you say me how to use selector?

@objc func sendCategoryIdToPackageSelectionVC(categoryId : Int){
        MarketVC.categoryId = categoryId
        self.performSegue(withIdentifier: "sequeGoToPackageSelection", sender: nil)
    }

func addTapFeatures(){
        taplabel1 = UITapGestureRecognizer(target: self, action: #selector(self.sendCategoryIdToPackageSelectionVC(categoryId:2)))
        taplabel1?.cancelsTouchesInView = false
        self.labelFirst.addGestureRecognizer(taplabel1!)
}

I get an error saying that the action selector doesn't refer to any objc method.

like image 661
Akif Demirezen Avatar asked Nov 18 '17 09:11

Akif Demirezen


1 Answers

i think, you can't directly use selector to pass parameter. try some thing like this you should create an @objc method that calls handleTap(modelObj:myModelObj).

@objc func someMethod() { // name this properly!
    handleTap(modelObj: myModelObj)
}

Then you can pass this as a selector:

#selector(someMethod)
like image 113
Syed Sadrul Ullah Sahad Avatar answered Oct 05 '22 02:10

Syed Sadrul Ullah Sahad