//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
Function
and creating a selector from this. You can't do this. A selector must have no arguments. So how do you pass theinfo
parameter then?Create a property in your class called
selectedCategory
:Before you call
addTarget
, assigninfo
to the above property:Create another method that calls
Function
with the parameter.Change your
addTarget
call to use abuttonClicked
as a selector: