“Unrecognized selector sent to instance” in swift

后端 未结 10 506
刺人心
刺人心 2020-12-10 10:36

I have no idea what I am doing wrong. I am also quite new to programming so I am not very good at debugging. This was a test app so that I can see how swift ties in with app

10条回答
  •  Happy的楠姐
    2020-12-10 11:23

    when using performSelector() methods your method (matching the selector) should be marked as @objc

    {  
        //...
        performSelector(Selector("myMethod"), withObject: nil, afterDelay: 0.3)
        //...
    
        // or in swift 2.2
        performSelector(#selector(ClassName.myMethod), withObject: nil, afterDelay: 0.3)
        //
    
        // or in swift 3
        perform(#selector(ClassName.myMethod), with: nil, afterDelay: 0.3)
        //
    
    }
    
    @objc private func myMethod() { }
    

提交回复
热议问题