How can use imageplayground in app

Asked on 03/06/2025

1 search

To use the Image Playground in your app, you can follow these steps as outlined in the What’s new in AppKit session:

  1. Initialize the Image Playground View Controller: Start by creating an instance of the Image Playground view controller and assign its delegate. The delegate will handle important lifecycle events, such as when image creation is finished or canceled.

  2. Set Up Initial Concepts and Source Imagery: If your app has specific context leading into the Image Playground experience, you can set up the view controller with initial concepts and source imagery. Concepts describe the expected contents of the output image, while the source image acts as a graphical reference.

  3. Present the View Controller: Present the view controller as a sheet to allow users to start creating images. Users can choose different images and concepts within the image creation sheet.

  4. Handle Image Creation Completion: Once the image is created, the view controller's delegate receives a callback with a reference to the image's file URL. This file URL is located in the app's sandboxed temporary directory.

  5. Insert the Image into Your UI: Use the file URL to insert the image into your user interface, and then dismiss the playground sheet.

  6. Consider Image Playground as an Image Source: If your app allows image insertion from the photo library, Finder, or Continuity Camera, consider adding Image Playground as another source of images.

This integration allows users to create images directly within your app using the Image Playground's capabilities, which run locally on the device without the need for external models or servers.