最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

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

Swift crifan 185浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
17 queries in 0.220 seconds, using 9.86MB memory