---
title: "messages(of:)"
framework: groupactivities
role: symbol
role_heading: Instance Method
path: "groupactivities/groupsessionmessenger/messages(of:)-626qo"
---

# messages(of:)

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

## Declaration

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

## Parameters

- `type`: The type of the doc://com.apple.documentation/documentation/Foundation/Data class. Specify Data.self.

## Discussion

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

- [messages(of:)](groupactivities/groupsessionmessenger/messages(of:)-jvoz.md)
- [GroupSessionMessenger.Messages](groupactivities/groupsessionmessenger/messages.md)
- [GroupSessionMessenger.MessageContext](groupactivities/groupsessionmessenger/messagecontext.md)
