One Logo Pool Ball
FoundationModels · IOS API REFERENCE

ImageReference

struct · iOS 27.0+ · SDK 27.1

struct ImageReference

A reference to an image in a session's transcript. Use `ImageReference` to allow the model to reference images from the transcript of the current `LanguageModelSession`. You can define an `ImageReference` as an argument to a `Tool`. Retrieve the referenced image from the transcript during the tool call. ```swift struct MyTool: Tool { @SessionProperty(\.history) var history @Generable struct Arguments { var image: ImageReference } public func call(arguments: Arguments) async throws -> Output { guard let imageAttachment = arguments.image.resolved(in: history) else { throw ImageToolError.imageNotFound(arguments.image.attachmentLabel) } let image = imageAttachment.cgImage ... } } ```

Members (4)

get · iOS 27.0+

attachmentLabel

TypeScript
get attachmentLabel(): string
Swift declaration
let attachmentLabel: String

The label of the referenced image.

get · iOS 27.0+

generatedContent

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

This instance represented as generated content. Conformance to this protocol is provided by the `@Generable` macro. You can provide a manual implementation to map values onto properties using different names. Use the generated content property as shown below, to manually return a new ``GeneratedContent`` with the properties you specify. ```swift struct Person: ConvertibleToGeneratedContent { var name: String var age: Int var generatedContent: GeneratedContent { GeneratedContent(properties: [ "firstName": name, "ageInYears": age ]) } } ``` - Important: If your type also conforms to ``ConvertibleFromGeneratedContent``, it is critical that this implementation be symmetrical with ``ConvertibleFromGeneratedContent/init(_:)``.

get · iOS 27.0+

generationSchema

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

An instance of the generation schema.

init · iOS 27.0+

init

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

Creates an instance from content generated by a model. Conformance to this protocol is provided by the `@Generable` macro. You can provide a manual implementation to map values onto properties using different names. To manually initialize your type from generated content, decode the values as shown below: ```swift struct Person: ConvertibleFromGeneratedContent { var name: String var age: Int init(_ content: GeneratedContent) { self.name = try content.value(forProperty: "firstName") self.age = try content.value(forProperty: "ageInYears") } } ``` - Important: If your type also conforms to ``ConvertibleToGeneratedContent``, it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``. - SeeAlso: `@Generable` macro ``Generable(description:)``

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ImageReference.resolved(in:)

This parameter hides a concrete Swift type.

All FoundationModels types →