I have a nested function like this and I want to call childFunc
when user tap to my button, but it does not work
class MyClass {
func parentFunc() {
button.addTarget(self, action: #selector(parentFunc().childFunc), for: .touchUpInside)
func childFunc() {
print("User tapped")
}
}
}
It raise error like this:
Value of tuple type '()' has no member 'childFunc'
Is there any way to perform childFunc
with #selector
?
Edit 1: I have use closure like this, But I think it's not a nice way because I have to make another function
class MyClass {
myClosure: () -> () = {}
func parentFunc() {
button.addTarget(self, action: #selector(runChildFunc), for: .touchUpInside)
func childFunc() {
print("User tapped")
}
myClosesure = childFunc
}
func runChildFunc() {
myClosure()
}
}