One Logo Pool Ball
FoundationModels · IOS API REFERENCE

GeneratedContent

struct · iOS 26.0+ · SDK 27.1

struct GeneratedContent

A type that represents structured, generated content. Generated content may contain a single value, an array, or key-value pairs with unique keys.

Members (19)

get · iOS 26.0+

generatedContent

TypeScript
get generatedContent(): GeneratedContent
Swift declaration
var generatedContent: GeneratedContent { get }

A representation of this instance.

get · iOS 26.0+

isComplete

TypeScript
get isComplete(): boolean
Swift declaration
var isComplete: Bool { get }

A Boolean value that indicates whether the generated content is complete.

get · iOS 26.0+

jsonString

TypeScript
get jsonString(): string
Swift declaration
var jsonString: String { get }

A JSON string representation of the generated content. Use this type to retrieve a JSON representation, like: ```swift // Create an object with properties. let content = GeneratedContent(properties: [ "name": "Johnny Appleseed", "age": 30, ]) // Print the output: {"name": "Johnny Appleseed", "age": 30} print(content.jsonString) ```

init · iOS 26.0+

init

TypeScript
static initPropertiesIdUniquingKeysWith(properties: Array<[string, SDKHandle]>, id: (GenerationID) | null, combine: ((arg0: GeneratedContent, arg1: GeneratedContent) => SDKHandle)): GeneratedContent
Swift declaration
init<S>(properties: S, id: GenerationID? = nil, uniquingKeysWith combine: (GeneratedContent, GeneratedContent) throws -> some ConvertibleToGeneratedContent) rethrows where S : Sequence, S.Element == (String, any ConvertibleToGeneratedContent)

Creates generated content from key-value pairs, resolving duplicate keys with a combining closure. The order of properties is important. For ``Generable`` types, the order must match the order properties in the types `schema`. You use this initializer to create generated content when you have a sequence of key-value tuples that might have duplicate keys. As the content is built, the initializer calls the `combine` closure with the current and new values for any duplicate keys. Pass a closure as `combine` that returns the value to use in the resulting content: The closure can choose between the two values, combine them to produce a new value, or even throw an error. The following example shows how to choose the first and last values for any duplicate keys: ```swift let content = GeneratedContent( properties: [("name", "John"), ("name", "Jane"), ("married", true)], uniquingKeysWith: { (first, _) in first } ) // GeneratedContent(["name": "John", "married": true]) ``` - Parameters: - properties: A sequence of key-value pairs to use for the new content. - id: A unique id associated with ``GeneratedContent``. - combine: A closure that is called with the values to resolve any duplicates keys that are encountered. The closure returns the desired value for the final content.

init · iOS 26.0+

init

TypeScript
static initPropertiesId(properties: SDKHandle, id?: (GenerationID) | null): GeneratedContent
Swift declaration
init(properties: KeyValuePairs<String, any ConvertibleToGeneratedContent>, id: GenerationID? = nil)

Creates generated content representing a structure with the properties you specify. The order of properties is important. For ``Generable`` types, the order must match the order properties in the types `schema`.

get · iOS 26.0+

debugDescription

TypeScript
get debugDescription(): string
Swift declaration
var debugDescription: String { get }

A string representation for the debug description.

get · iOS 26.0+

generationSchema

TypeScript
static get generationSchema(): GenerationSchema
Swift declaration
static var generationSchema: GenerationSchema { get }

An instance of the generation schema.

get · iOS 26.0+

id

TypeScript
get id(): (GenerationID) | null
Swift declaration
var id: GenerationID?

A unique id that is stable for the duration of a generated response. A ``LanguageModelSession`` produces instances of ``GeneratedContent`` that have a non-nil `id`. When you stream a response, the `id` is the same for all partial generations in the response stream. Instances of ``GeneratedContent`` that you produce manually with initializers have a nil `id` because the framework didn't create them as part of a generation.

set · iOS 26.0+

id

TypeScript
set id(value: (GenerationID) | null)
Swift declaration
var id: GenerationID?

A unique id that is stable for the duration of a generated response. A ``LanguageModelSession`` produces instances of ``GeneratedContent`` that have a non-nil `id`. When you stream a response, the `id` is the same for all partial generations in the response stream. Instances of ``GeneratedContent`` that you produce manually with initializers have a nil `id` because the framework didn't create them as part of a generation.

init · iOS 26.0+

init

TypeScript
static initJson(json: string): GeneratedContent
Swift declaration
init(json: String) throws

Creates equivalent content from a JSON string. The JSON string you provide may be incomplete. This is useful for correctly handling partially generated responses. ```swift @Generable struct NovelIdea { let title: String } let partial = #"{"title": "A story of"# let content = try GeneratedContent(json: partial) let idea = try NovelIdea(content) print(idea.title) // A story of ```

init · iOS 26.0+

init

TypeScript
static initKindId(kind: GeneratedContent_Kind, id?: (GenerationID) | null): GeneratedContent
Swift declaration
init(kind: GeneratedContent.Kind, id: GenerationID? = nil)

Creates content with the specified kind and generation identifier. This initializer provides a convenient way to create content from its kind representation. - Parameters: - kind: The kind of content to create. - id: An optional ``GenerationID`` to associate with this content.

get · iOS 26.0+

kind

TypeScript
get kind(): GeneratedContent_Kind
Swift declaration
var kind: GeneratedContent.Kind { get }

The representation of the generated content. This property provides access to the content in a strongly-typed enumeration representation, preserving the hierarchical structure of the data and the data's ``GenerationID`` values.

method · iOS 26.0+

value

TypeScript
valueForProperty(property: string): (number) | null
Swift declaration
func value<Value>(_ type: Value?.Type = Value?.self, forProperty property: String) throws -> Value? where Value : ConvertibleFromGeneratedContent

Reads an optional, concrete generable type from a named property.

method · iOS 26.0+

value

TypeScript
valueForProperty41093(property: string): number
Swift declaration
func value<Value>(_ type: Value.Type = Value.self, forProperty property: String) throws -> Value where Value : ConvertibleFromGeneratedContent

Reads a concrete generable type from a named property.

method · iOS 26.0+

value

TypeScript
value(): number
Swift declaration
func value<Value>(_ type: Value.Type = Value.self) throws -> Value where Value : ConvertibleFromGeneratedContent

Reads a top level, concrete partially generable type from a named property.

init · iOS 26.0+

init

TypeScript
static initElementsId(elements: Array<SDKHandle>, id?: (GenerationID) | null): GeneratedContent
Swift declaration
init<S>(elements: S, id: GenerationID? = nil) where S : Sequence, S.Element == any ConvertibleToGeneratedContent

Creates content representing an array of elements you specify.

init · iOS 26.0+

init

TypeScript
static initId(value: SDKHandle, id: GenerationID): GeneratedContent
Swift declaration
init(_ value: some ConvertibleToGeneratedContent, id: GenerationID)

Creates content that contains a single value with a custom generation identifier. - Parameters: - value: The underlying value. - id: The ``GenerationID`` for this content.

init · iOS 26.0+

init

TypeScript
static init(content: GeneratedContent): GeneratedContent
Swift declaration
init(_ content: GeneratedContent) throws

Creates generated content from another value. This is used to satisfy `Generable.init(_:)`.

init · iOS 26.0+

init

TypeScript
static init83790(value: SDKHandle): GeneratedContent
Swift declaration
init(_ value: some ConvertibleToGeneratedContent)

Creates content that contains a single value. - Parameters: - value: The underlying value.

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →