"Unrecognized Selector Sent to Instance" Error

Hi There I have the problem with this code

    private func initializer(){
    let gesture = UITapGestureRecognizer(target: self, action: Selector(("onTapLabel")))
    isUserInteractionEnabled = true

    font = UIFont(name: "icomoon", size: font.pointSize)
    if isChecked{
        text = ""
        text = ""
internal func onTapLabel(){

I had used this code in swift 2 but now I can't use it!

Use #selector instead of Selector()

1 Like

it's shows this error
Argu ment of '#selector' does not refer to an '@objc' method, property, or initializer

Add @objc to your function, so:

@objc func onTapLabel() {
1 Like


Remove " from the selector. It's a type-safe mechanism that does not require strings anymore.

1 Like

Remove the quotes around the function. It should just be #selector(onTapLabel)

1 Like

Thanks :heart: Fixed

Terms of Service

Privacy Policy

Cookie Policy