[英]JSQMessages cannot override method Swift 3
For some reason I cannot override methods in Swift 3 using JSQMessages. 出于某种原因,我无法使用JSQMessages覆盖Swift 3中的方法。
These methods are defined in the JSQMessagesCollectionViewDataSource
这些方法在JSQMessagesCollectionViewDataSource
中定义
public func senderDisplayName() -> String!
public func senderId() -> String!
When I subclass JSQMessagesViewController I try to implement the methods as such: 当我继承JSQMessagesViewController时,我尝试实现这样的方法:
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. 当我删除覆盖时,它说它与Obj-C选择器冲突。
I have implemented this functionality in swift 3 with following Properties 我在swift 3中使用以下属性实现了此功能
self.senderId = "my ID"
self.senderDisplayName = "Wozniac"
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): 根据SE-0117:允许区分公共访问和公共覆盖 ,引入open
关键字,导入的Objective-C代码的规则是(强调我的):
Objective-C classes and methods are always imported as open . Objective-C类和方法始终导入为open 。 This means that the synthesized header for an Objective-C class would pervasively replace public with open in its interface. 这意味着Objective-C类的合成头将在其接口中普遍地用open替换public 。
Of course, assuming JSQMessages
is still implemented in pure Objective-C. 当然,假设JSQMessages
仍然在纯Objective-C中实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.