How does #Playground work?
Asked on 06/16/2025
2 searches
The #Playground feature in Xcode is a powerful tool for experimenting with code and prompts, especially when working with large language models. It allows developers to quickly iterate on their code without needing to rebuild and rerun their entire app. Here are some key points about how it works:
-
Integration with Xcode: You can add a Playground to any code file in your project. This feature is similar to SwiftUI previews, providing immediate feedback by displaying the model's response in the canvas on the right side of Xcode.
-
Prompt Testing: Playgrounds are particularly useful for testing and refining prompts when working with on-device foundation models. You can write prompts and see the model's output instantly, which is crucial for effective prompt engineering.
-
Iterative Development: The Playground macro allows you to iterate on any code, not just UI code. This makes it a versatile tool for understanding existing code and trying out new ideas.
-
Access to Project Types: In a Playground, your code can access all the types defined in your project, allowing for comprehensive testing and experimentation.
-
Open Source: The Playground macro is being open-sourced, which means it will be available for Swift developers on other platforms as well.
For more detailed information, you can refer to the session Meet the Foundation Models framework (21:02) and What’s new in Xcode (01:42).

Meet the Foundation Models framework
Learn how to tap into the on-device large language model behind Apple Intelligence! This high-level overview covers everything from guided generation for generating Swift data structures and streaming for responsive experiences, to tool calling for integrating data sources and sessions for context management. This session has no prerequisites.

Explore prompt design & safety for on-device foundation models
Design generative AI experiences that leverage the strengths of the Foundation Models framework. We’ll start by showing how to design prompts for the on-device large language model at the core of Apple Intelligence. Then, we’ll introduce key ideas around AI safety, and offer concrete strategies to make your generative AI features safe, reliable, and delightful.

Platforms State of the Union
Discover the newest advancements on Apple platforms.