3

For some reason I cannot override methods in Swift 3 using JSQMessages.

These methods are defined in the JSQMessagesCollectionViewDataSource

public func senderDisplayName() -> String!

public func senderId() -> String!

When I subclass JSQMessagesViewController I try to implement the methods as such:

override func senderId() -> String {
    return User.Wozniak.rawValue
}

override public func senderDisplayName() -> String! {
    return getName(.Wozniak)
}

However I get the error that it does not override any method from its super class. When I remove override it says it conflicts with an Obj-C selector.

user3440639
  • 185
  • 2
  • 12
  • Just curious, but what happens if you add the "@objc" attribute to the functions? – BonanzaDriver May 09 '17 at 02:59
  • Similar issues [here](http://stackoverflow.com/q/41344287/3687801) and [here](http://stackoverflow.com/q/25788782/3687801). Take a look if any of them solves your problem. – nayem May 09 '17 at 03:33
  • @nayem hii have u worked with JSQMessagesViewController i need help from u – Dilip Tiwari Aug 07 '18 at 06:10

2 Answers2

1

I have implemented this functionality in swift 3 with following Properties

self.senderId = "my ID"
self.senderDisplayName = "Wozniac"
Wasim Malek
  • 123
  • 7
0

You might try this instead:

open override func senderId() -> String {
    ...
}

but I'm not sure if it will fix your issue completely.

According to SE-0117: Allow distinguishing between public access and public overridability, which introduces the open keyword, the rules for imported Objective-C code are (emphasis mine):

Objective-C classes and methods are always imported as open. This means that the synthesized header for an Objective-C class would pervasively replace public with open in its interface.

Of course, assuming JSQMessages is still implemented in pure Objective-C.

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85