Contents

maximumCount(_:)

Enforces a maximum number of elements in the array.

Declaration

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

Mentioned in

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.

@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]
}

See Also

Getting the maximum value