Swift 将字符串转换为函数名 (#selector)

Swift convert string to function name (#selector)

我做了一个接收字符串的函数。该字符串必须转换为函数名称,然后作为 #selector 参数传递。我试过了,但没用:

func setFunctionWithTap(functionName: String) {
    let tap = UITapGestureRecognizer(target: self, action: #selector(functionName))
    ...
}

你能告诉我这是否可能吗?

改用Selector initializer that accepts a string

let tap = UITapGestureRecognizer(target: self, action: Selector(functionName))