images(for:style:limit:)
Starts the creation of images based on the description and style information you provide.
Declaration
final func images(for concepts: [ImagePlaygroundConcept], style: ImagePlaygroundStyle, limit: Int) -> some AsyncSequence<ImageCreator.CreatedImage, any Error>
Parameters
- concepts:
The elements that describe the expected contents of the image.
- style:
The style you want the model to apply to the output image. It is a programmer error to specify a style that’s not in the
availableStylesproperty. - limit:
The maximum number of images you want the system to create. The system limits the maximum number of images to 4.
Return Value
An asynchronous stream you use to receive the images.
Discussion
Call this method to start the image generation process with the specified parameters. The method executes asynchronously and returns the images on the provided AsyncSequence object. The following example configures an image creator, starts the creation of the images, and processes the generated images as they arrive.
do {
let creator = try await ImageCreator()
guard let style = creator.availableStyles.first else { return }
let images = creator.images(
for: [.text("A cat wearing mittens.")]
style: style,
limit: 4)
// Receive the images.
for try await image in images {
let anImage = image.cgImage
// Do something with the image.
}
}
catch ImageCreator.Error.notSupported {
print(“Image creation not supported on the current device.”)
}