0

I'm using MessageKit, and it requires that you have model objects that adopt the protocol MessageType. Most of the examples involves structs following the protocol but unfortunately I'm using a third party API library to interact with a site's API, and they have all their models as classes (in Objective-C).

So when I try to adopt the protocol with extension ServerMessage: MessageType I get the error

Inheritance from non-protocol type

How can I make it work with my Objective-C class?

Doug Smith
  • 29,668
  • 57
  • 204
  • 388

1 Answers1

1

Any protocol that works with a struct is bound to work with a class. The limitation is the other way around. It is hard to provide an answer without a code snippet, but I do not see why it should not work.

@objc class ServerMessage: NSObject {

}

protocol MessageType {
    var sender: Any { get }
}

extension ServerMessage: MessageType {
    var sender: Any { return () }
}

This dummy code does not provide any errors. Maybe you had a typo somewhere?