<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/DynamicInstructionsForEach/init(_:id:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels26DynamicInstructionsForEachV_2id7contentACyxq_q0_Gx_s7KeyPathCy7ElementQzq_Gq0_AJctcfc"
  },
  "title" : "init(_:id:content:)"
}
-->

# init(_:id:content:)

Creates dynamic instructions that produce content for each element of a collection.

```
init(_ data: Data, id: KeyPath<Data.Element, ID>, @DynamicInstructionsBuilder content: @escaping (Data.Element) -> Content)
```

## Parameters

`data`

The collection whose elements each produce content.

`id`

A key path to a property that uniquely identifies each element.

`content`

A builder closure that produces the dynamic instructions for an element.

## Discussion

Don’t create this type directly. Instead, use [`DynamicInstructions.ForEach`](/documentation/FoundationModels/DynamicInstructions/ForEach) within the
`body` of your [`DynamicInstructions`](/documentation/FoundationModels/DynamicInstructions).

---

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)