<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/GenerationGuide/element(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels15GenerationGuideV7elementyACySayqd__GGACyqd__GAERszlFZ"
  },
  "title" : "element(_:)"
}
-->

# element(_:)

Enforces a guide on the elements within the array.

```
static func element<Element>(_ guide: GenerationGuide<Element>) -> GenerationGuide<[Element]> where Value == [Element]
```

## Discussion

An `element` generation guide may be used when you want to apply guides to
the values a model produces within an array. For example, you may want to
generate an array of integers, where all the integers are in the range 0-9.

```swift
@Generable
struct FortuneCookie {
    @Guide(description: "A fortune from a fortune cookie")
    var name: String

    @Guide(description: "A list lucky numbers", .element(.range(0...9)), .count(4))
    var luckyNumbers: [Int]
}
```

---

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)