Playground 的使用

Asked on 2025-11-27

1 search

Playgrounds are a powerful tool in Xcode that allow developers to quickly iterate on code and experiment with new ideas. They provide a live feedback environment similar to SwiftUI previews, where you can see the results of your code execution in a dedicated Canvas tab. This feature is particularly useful for understanding existing code and trying out new concepts without having to rebuild and rerun your entire app.

For example, in the session "What’s new in Xcode" from WWDC 2025, Playgrounds are demonstrated as a way to debug and explore the structure of a landmark in an app. By using the Playground macro, developers can import the Playgrounds module and examine data directly in the canvas, making it easier to identify and fix issues, such as incorrect coordinates for a landmark.

Additionally, Playgrounds are integrated with the Foundation Models framework, allowing developers to test and iterate on prompts for large language models directly within Xcode. This integration helps in optimizing prompts and understanding latency, which is crucial for building app experiences powered by AI.

For more detailed information, you can refer to the session What’s new in Xcode (05:06) where Playgrounds are discussed in the context of debugging and code exploration.

Playground 的使用 | Ask WWDC