Home>
I am using chatkit to create a chat, but an error appears in one sentence of extension ChatViewController: MessagesDataSource. I think I have implemented all the required methods to resolve the error, but it doesn't. I would like to tell you what went wrong.
import UIKit
import MessageKit
public protocol MessageType {
var sender: Sender {get}
var messageId: String {get}
var sentDate: Date {get}
var kind: MessageKind {get}
}
public struct SenderType {
public let id: String
public let displayName: String
}
class ChatViewController: MessagesViewController {
override func viewDidLoad () {
super.viewDidLoad ()
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
}
}
let sender = SenderType (id: "any_unique_id", displayName: "Steven")
let messages: [MessageType] = []
extension ChatViewController: MessagesDataSource {
// Here you see Type 'ChatViewController' does not conform to protocol 'MessagesDataSource'
func currentSender ()->SenderType {
return SenderType (id: "any_unique_id", displayName: "Steven")
}
func numberOfSections (in messagesCollectionView: MessagesCollectionView)->Int {
return messages.count
}
func messageForItem (at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView)->MessageType {
return messages [indexPath.section]
}
}
extension ChatViewController: MessagesDisplayDelegate, MessagesLayoutDelegate {}
-
Answer # 1
Related articles
- ruby on rails - an error occurred while setting up the production environment to deploy
- ruby on rails 6 - i want to solve the error that occurred while implementing the product listing function
- java - an error occurred while casting the reference type
- error occurred while trying to register data (add column) from python to salesforce
- linux - i want to solve the error when i brew upgrade, errno::eacces: permission denied @ dir_s_mkdir
- ios - weakpassword of the error handle does not work
- i want to solve a php syntax error, unexpected end of file
- python - i want you to resolve the error that occurred when using wget on jupyter notebook
- javascript - i want to solve cors error by using credential (cookie)
- bash - i want to solve the error of command not found of gulp in the terminal
- i want to resolve the error that occurred in cocnvim
- i want to solve the error of the wrong interpreter by executing /****sh (python ****py)
- ruby - nomethoderror in bookscontroller#create i want to solve the error and implement the posting function
- ruby - i want to solve the error statement
- php headerphp include does not solve the error
- ios - i identified the error with exception breakpoint, but i don't know the inappropriate part [exc_bad_access]
- ios - self error in do-catch [i want to call urlsession from another class ]
- nginx - i got a git error: command while doing bundle install on ec2, so please resolve it
- ios - unexpectedly found nil error when selecteduser is nil
- ruby - i got a: id => nil error while implementing the user removal feature, so i'd like to ask for a solution
Related questions
- ios - core bluetooth data exchange
- ios - thread 1: exception: error is displayed!
- ios - about processing when data could not be obtained by api
- ios - about the mechanism that can pass by value at the time of screen transition in segue
- ios - i want to display the initial text value of uitextfield in swiftui
- ios - it is about line breaks when using uitextview wrapped in swift ui
- ios - i want to return to the first initial screen after logging out
- ios - i want to load uitableview by pressing a button
- ios - swift completionhandler how to make your own closure
- [ios] effect of setting enable bitcode to false
As advised last time, the MessageType protocol and SenderType protocol are not defined by yourself
must be deleted.
And as a structure conforming to the SenderType protocol
For example, create a User structure
IfSenderType (id: "any_unique_id", displayName: "Steven")
Not
User (senderId: "any_unique_id", displayName: "Steven")
, the error will disappear for the time being.