Contents

messages(of:)

Returns the asynchronous sequence of messages that contain a generic data object.

Declaration

final func messages(of type: Data.Type) -> GroupSessionMessenger.Messages<Data>

Parameters

  • type:

    The type of the Data class. Specify Data.self.

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 dataMessage in sessionMessenger.messages(of: Data.self) {
        self.processDataMessage(dataMessage)
    }
}

See Also

Receiving data from other participants