//This is the function which contain my button action programatically
func didSetCategory(info: FitnessCenterModel) {
myButton.addTarget(self, action: #selector(Function(d: info)), for: .touchUpInside)
}
// my selector function for the button target
func Function(d:FitnessCenterModel ) {
print(info)
}
but i am not able to pass as the compiler is throwing an error "Argument of '#selector' does not refer to an '@Objc' method, property, or initialzer
A selector does not refer to a method call, but just the method itself.
What you are doing here:
is passing an argument to
Functionand creating a selector from this. You can't do this. A selector must have no arguments. So how do you pass theinfoparameter then?Create a property in your class called
selectedCategory:Before you call
addTarget, assigninfoto the above property:Create another method that calls
Functionwith the parameter.Change your
addTargetcall to use abuttonClickedas a selector: