Unable to use custom class in a protocol with @objc attribute?

后端 未结 4 1799
独厮守ぢ
独厮守ぢ 2021-01-04 11:55

I am trying to create a protocol for JSON loading delegation, JSONLoaderDelegate. My other class, called JSONLoader, is supposed to dispatch events

4条回答
  •  走了就别回头了
    2021-01-04 12:27

    I faced this problem as I had a class MyConnection that had no parent class. Like this.

    public class MyConnection {
    }
    

    I can't put @objc before this, as I get a warning

    Only classes that inherit from NSObject can be declared @objc

    So I changed the class to be inherited from NSObject. Like this

    public class MyConnection: NSObject {
    }
    

提交回复
热议问题