Apple Developer onepage/WWDC26
#WWDC26#Xcode#Swift2026-06-13 · Short

在任何 Swift 檔案裡 Play(ground):把探索縮短成一個 macro

這支短片介紹 `#Playground` macro:不用離開目前 codebase,就能在 Swift 檔案裡跑小片段、看結果、探索 API。完整 WWDC26 脈絡則把它放進 Xcode 27 的輕量原型、AI feature 測試與日常開發工作流。

// 一句話結論

`#Playground` 的價值不是取代 tests 或 previews,而是把「我先試一下」變成專案內可保存、可分享、可快速迭代的小型實驗場。

Apple Developer · WWDC26 · Video ID: g2HpyqlXWpkYouTube short
Content map

這個短片其實在講 Xcode 工作流的四個摩擦點

Explore

探索 API 不必切到另一個 playground bundle

短片重點是 `#Playground` 可以放在任何 Swift 檔案中,讓你在原本的型別、helper 或 service 附近嘗試片段。

Context

實驗保留在專案語境裡

比起把 sample code 貼到外部 scratch file,macro 旁邊就是真實 app code,因此更容易使用同一組 model、fixture 與 dependency。

Feedback

Canvas 結果讓服務或 UI 想法快速成形

WWDC26 Xcode 27 session 顯示 standalone Swift file 也能顯示 playground results 與 UI previews,適合分享輕量想法或驗證資料呈現。

Boundary

Playground 不是 release guarantee

它適合探索與縮短 feedback loop;真正要保證行為,仍需要 unit tests、UI tests、Evaluations、Instruments 或 CI pipeline。

Decision map

什麼時候用 #Playground,什麼時候不要

1

用於 API sketch 與 model transformation

你想看某段 parsing、formatting、Foundation Models prompt 或小型 data pipeline 的 immediate output,這很適合放進 `#Playground`。

2

用於 service 邏輯的第一輪校準

Apple 在 Evaluations framework session 中示範用 `#Playground` 嘗試 book tagging service,先看輸出品質,再決定要調 prompt、規則或 evaluator。

3

不要用它取代回歸測試

一旦行為需要跨版本保證,就要移到 Swift Testing / XCTest / Evaluations。Playground 的產物可以啟發 test case,但不應是唯一真相。

4

小心目標平台與環境差異

Canvas destination、macOS / iOS runtime、Apple Intelligence 可用性、network 與 entitlement 都可能影響結果。實驗通過不代表所有裝置都通過。

重點 1:#Playground 把 scratchpad 往 codebase 內移

傳統 playground 很適合教學與 isolated experiment,但一旦要接真實 app model、formatter、service 或 Swift package,就容易脫離專案脈絡。`#Playground` macro 的方向是把小實驗放回 Swift 檔案中,讓你在編輯真實程式碼時就能觀察片段輸出。

實務上建議把 playground blocks 當成「可閱讀的探索註記」。如果它開始依賴太多 mutable global state、網路、登入 session 或裝置能力,表示該把它升級成測試或 demo target。

重點 2:對 AI / Foundation Models 開發尤其有用,但更需要 evaluation

WWDC26 Evaluations framework session 裡的情境是:開發者用 `#Playground` 快速嘗試 book tagging service,觀察 tag 數量、是否包含書名、是否有多字詞等品質問題。這種探索很適合 prompt / tool / formatter 的早期調整。

但 AI feature 的輸出不穩定,不能只靠肉眼看幾次 playground output。當規格明確後,應把期待行為整理成 dataset、evaluator、threshold 與 regression workflow。

重點 3:與 Xcode 27 的輕量原型能力互補

官方「What's new in Xcode 27」也提到,新的 untitled project、standalone Swift file、canvas results 與 UI previews 讓開發者可以更快分享想法。`#Playground` 在這裡扮演的是低成本驗證層:先證明概念成立,再搬進正式 target。

來源

主要來源:Apple Developer YouTube short「Play(ground) in any Swift file」、官方「Xcode Tips and Tricks Group Lab」、「What's new in Xcode 27」與「Meet the Evaluations framework」。

// TL;DR