<!--
{
  "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/maximumCount(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels15GenerationGuideV12maximumCountyACySayqd__GGSiAERszlFZ"
  },
  "title" : "maximumCount(_:)"
}
-->

# maximumCount(_:)

Enforces a maximum number of elements in the array.

```
static func maximumCount<Element>(_ count: Int) -> GenerationGuide<[Element]> where Value == [Element]
```

## Discussion

The bounds are inclusive.

A `maximumCount` generation guide may be used when you want to ensure the
model produces a number of array elements less than or equal to to some
maximum value, such as the number of items in a game’s shop.

```swift
@Generable
struct Shop {
    @Guide(description: "A creative name for a shop in a fantasy RPG")
    var name: String

    @Guide(description: "A list of items for sale", .maximumCount(10))
    var inventory: [ShopItem]
}
```

---

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)