<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/TaskGroup/Iterator",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScG8IteratorV"
  },
  "title" : "TaskGroup.Iterator"
}
-->

# TaskGroup.Iterator

A type that provides an iteration interface
over the results of tasks added to the group.

```
struct Iterator
```

## Overview

The elements returned by this iterator
appear in the order that the tasks *completed*,
not in the order that those tasks were added to the task group.

This iterator terminates after all tasks have completed.
After iterating over the results of each task,
it’s valid to make a new iterator for the task group,
which you can use to iterate over the results of new tasks you add to the group.
For example:

```
group.addTask { 1 }
for await r in group { print(r) }

// Add a new child task and iterate again.
group.addTask { 2 }
for await r in group { print(r) }
```

> SeeAlso: `TaskGroup.next()`

## Topics

### Instance Methods

[`func cancel()`](/documentation/Swift/TaskGroup/Iterator/cancel())

[`func next() async -> TaskGroup<ChildTaskResult>.Iterator.Element?`](/documentation/Swift/TaskGroup/Iterator/next())

Advances to and returns the result of the next child task.

[`func next(isolation: isolated (any Actor)?) async -> TaskGroup<ChildTaskResult>.Iterator.Element?`](/documentation/Swift/TaskGroup/Iterator/next(isolation:))

Advances to and returns the result of the next child task.

### Type Aliases

[`typealias Element`](/documentation/Swift/TaskGroup/Iterator/Element)

### Default Implementations

[AsyncIteratorProtocol Implementations](/documentation/Swift/TaskGroup/Iterator/AsyncIteratorProtocol-Implementations)

## Relationships

### Conforms To

[`AsyncIteratorProtocol`](/documentation/Swift/AsyncIteratorProtocol)

---

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)