MessagesDataSource
public protocol MessagesDataSource: AnyObject
An object that adopts the MessagesDataSource protocol is responsible for providing
the data required by a MessagesCollectionView.
-
The
Senderof new messages in theMessagesCollectionView.Declaration
Swift
func currentSender() -> Sender -
isFromCurrentSender(message:)Default implementationA helper method to determine if a given message is from the current
Sender.Default Implementation
Declaration
Swift
func isFromCurrentSender(message: MessageType) -> BoolParameters
messageThe message to check if it was sent by the current
Sender. -
The message to be used for a
MessageCollectionViewCellat the givenIndexPath.Declaration
Swift
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageTypeParameters
indexPathThe
IndexPathof the cell.messagesCollectionViewThe
MessagesCollectionViewin which the message will be displayed. -
The number of sections to be displayed in the
MessagesCollectionView.Declaration
Swift
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> IntParameters
messagesCollectionViewThe
MessagesCollectionViewin which the messages will be displayed. -
numberOfItems(inSection:in:)Default implementationThe number of cells to be displayed in the
MessagesCollectionView.Note
The default implementation of this method returns 1. Putting each message in its own section.Default Implementation
Declaration
Swift
func numberOfItems(inSection section: Int, in messagesCollectionView: MessagesCollectionView) -> IntParameters
sectionThe number of the section in which the cells will be displayed.
messagesCollectionViewThe
MessagesCollectionViewin which the messages will be displayed. -
cellTopLabelAttributedText(for:at:)Default implementationThe attributed text to be used for cell’s top label.
The default value returned by this method is
nil.Default Implementation
Declaration
Swift
func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?Parameters
messageThe
MessageTypethat will be displayed by this cell.indexPathThe
IndexPathof the cell.messagesCollectionViewThe
MessagesCollectionViewin which this cell will be displayed. -
messageTopLabelAttributedText(for:at:)Default implementationThe attributed text to be used for message bubble’s top label.
The default value returned by this method is
nil.Default Implementation
Declaration
Swift
func messageTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?Parameters
messageThe
MessageTypethat will be displayed by this cell.indexPathThe
IndexPathof the cell.messagesCollectionViewThe
MessagesCollectionViewin which this cell will be displayed. -
messageBottomLabelAttributedText(for:at:)Default implementationThe attributed text to be used for cell’s bottom label.
The default value returned by this method is
nil.Default Implementation
Declaration
Swift
func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?Parameters
messageThe
MessageTypethat will be displayed by this cell.indexPathThe
IndexPathof the cell.messagesCollectionViewThe
MessagesCollectionViewin which this cell will be displayed.
MessagesDataSource Protocol Reference