MessagesDataSource

public protocol MessagesDataSource: AnyObject

An object that adopts the MessagesDataSource protocol is responsible for providing the data required by a MessagesCollectionView.

  • The Sender of new messages in the MessagesCollectionView.

    Declaration

    Swift

    func currentSender() -> Sender
  • isFromCurrentSender(message:) Default implementation

    A helper method to determine if a given message is from the current Sender.

    Note

    The default implementation of this method checks for equality between the message’s Sender and the current Sender.

    Default Implementation

    Declaration

    Swift

    func isFromCurrentSender(message: MessageType) -> Bool

    Parameters

    message

    The message to check if it was sent by the current Sender.

  • The message to be used for a MessageCollectionViewCell at the given IndexPath.

    Declaration

    Swift

    func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType

    Parameters

    indexPath

    The IndexPath of the cell.

    messagesCollectionView

    The MessagesCollectionView in which the message will be displayed.

  • The number of sections to be displayed in the MessagesCollectionView.

    Declaration

    Swift

    func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int

    Parameters

    messagesCollectionView

    The MessagesCollectionView in which the messages will be displayed.

  • numberOfItems(inSection:in:) Default implementation

    The 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) -> Int

    Parameters

    section

    The number of the section in which the cells will be displayed.

    messagesCollectionView

    The MessagesCollectionView in which the messages will be displayed.

  • cellTopLabelAttributedText(for:at:) Default implementation

    The 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

    message

    The MessageType that will be displayed by this cell.

    indexPath

    The IndexPath of the cell.

    messagesCollectionView

    The MessagesCollectionView in which this cell will be displayed.

  • The 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

    message

    The MessageType that will be displayed by this cell.

    indexPath

    The IndexPath of the cell.

    messagesCollectionView

    The MessagesCollectionView in which this cell will be displayed.

  • The 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

    message

    The MessageType that will be displayed by this cell.

    indexPath

    The IndexPath of the cell.

    messagesCollectionView

    The MessagesCollectionView in which this cell will be displayed.