最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]Swift出错:Type does not conform to protocol xxxDelegate

Swift crifan 3517浏览 0评论

swift代码:

protocol MessageDelegate {
   
func newMessageSent(sentMessage:Message)
   
func newMessageReceived(newMessage:Message)
}
class ConversationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MessageTableDelegate, MessageDelegate {
。。。
   
    var messageDelegate: MessageDelegate?

Type ‘ConversationViewController’ does not conform to protocol ‘MessageDelegate’

搜:

swift protocol optional

参考:

ios – How to define optional methods in Swift protocol? – Stack Overflow

Optional Protocol Methods in Pure Swift

Optional Protocol – Swift Must Know Tips

The Swift Programming Language (Swift 2.1): Protocols

变成:

【总结】

protocol MessageDelegate {
//    func newMessageSent(sentMessage:Message)
    func newMessageReceived(newMessage:Message)
}

extension MessageDelegate {
   
func newMessageSent(sentMessage:Message) {
       
//empty here
    }

}

即可。

转载请注明:在路上 » [已解决]Swift出错:Type does not conform to protocol xxxDelegate

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.167 seconds, using 22.09MB memory