<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GroupActivities",
  "identifier" : "/documentation/GroupActivities/GroupSessionMessenger/messages(of:)-626qo",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Group Activities",
      "GroupActivities"
    ],
    "preciseIdentifier" : "s:15GroupActivities0A16SessionMessengerC8messages2ofAC8MessagesVy_10Foundation4DataVGAJm_tF"
  },
  "title" : "messages(of:)"
}
-->

# messages(of:)

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

```
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

Call this method to receive the messages that other participants send to the
group. This method returns a [`GroupSessionMessenger.Messages`](/documentation/GroupActivities/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)
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)