Swift 4 using selector with Multiple Parameters
10,347
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)
Author by
Akif Demirezen
Updated on July 07, 2022Comments
-
Akif Demirezen almost 2 years
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.