generatedContent
TypeScriptget generatedContent(): GeneratedContentSwift declarationvar generatedContent: GeneratedContent { get }A representation of this instance.
struct · iOS 26.0+ · SDK 27.1
struct GeneratedContentA type that represents structured, generated content. Generated content may contain a single value, an array, or key-value pairs with unique keys.
get generatedContent(): GeneratedContentSwift declarationvar generatedContent: GeneratedContent { get }A representation of this instance.
get isComplete(): booleanSwift declarationvar isComplete: Bool { get }A Boolean value that indicates whether the generated content is complete.
get jsonString(): stringSwift declarationvar 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) ```
static initPropertiesIdUniquingKeysWith(properties: Array<[string, SDKHandle]>, id: (GenerationID) | null, combine: ((arg0: GeneratedContent, arg1: GeneratedContent) => SDKHandle)): GeneratedContentSwift declarationinit<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.
static initPropertiesId(properties: SDKHandle, id?: (GenerationID) | null): GeneratedContentSwift declarationinit(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 debugDescription(): stringSwift declarationvar debugDescription: String { get }A string representation for the debug description.
static get generationSchema(): GenerationSchemaSwift declarationstatic var generationSchema: GenerationSchema { get }An instance of the generation schema.
get id(): (GenerationID) | nullSwift declarationvar 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 id(value: (GenerationID) | null)Swift declarationvar 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.
static initJson(json: string): GeneratedContentSwift declarationinit(json: String) throwsCreates 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 ```
static initKindId(kind: GeneratedContent_Kind, id?: (GenerationID) | null): GeneratedContentSwift declarationinit(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 kind(): GeneratedContent_KindSwift declarationvar 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.
valueForProperty(property: string): (number) | nullSwift declarationfunc value<Value>(_ type: Value?.Type = Value?.self, forProperty property: String) throws -> Value? where Value : ConvertibleFromGeneratedContentReads an optional, concrete generable type from a named property.
valueForProperty41093(property: string): numberSwift declarationfunc value<Value>(_ type: Value.Type = Value.self, forProperty property: String) throws -> Value where Value : ConvertibleFromGeneratedContentReads a concrete generable type from a named property.
value(): numberSwift declarationfunc value<Value>(_ type: Value.Type = Value.self) throws -> Value where Value : ConvertibleFromGeneratedContentReads a top level, concrete partially generable type from a named property.
static initElementsId(elements: Array<SDKHandle>, id?: (GenerationID) | null): GeneratedContentSwift declarationinit<S>(elements: S, id: GenerationID? = nil) where S : Sequence, S.Element == any ConvertibleToGeneratedContentCreates content representing an array of elements you specify.
static initId(value: SDKHandle, id: GenerationID): GeneratedContentSwift declarationinit(_ 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.
static init(content: GeneratedContent): GeneratedContentSwift declarationinit(_ content: GeneratedContent) throwsCreates generated content from another value. This is used to satisfy `Generable.init(_:)`.
static init83790(value: SDKHandle): GeneratedContentSwift declarationinit(_ value: some ConvertibleToGeneratedContent)Creates content that contains a single value. - Parameters: - value: The underlying value.
No declarations were skipped in this snapshot.