Contents

messages(of:)

Returns the asynchronous sequence of messages that match the app-specific type.

Declaration

final func messages<Message>(of type: Message.Type) -> GroupSessionMessenger.Messages<Message> where Message : Decodable, Message : Encodable

Parameters

  • type:

    The class of the custom type you use to package the message contents.

Discussion

Call this method to receive the messages that other participants send to the group. This method returns a GroupSessionMessenger.Messages structure, which conforms to the AsyncSequence protocol. This sequence contains all, some, or none of the messages sent over time. You retrieve messages by iterating over them using an asynchronous for-in loop, as shown in the following example:

let sessionMessenger = GroupSessionMessenger(session: groupSession)

async {
    for await move in sessionMessenger.messages(of: TicTacToe.Move.self) {
        self.board.addMove(move)
    }
}

See Also

Receiving data from other participants