Skip to content

Commit ecaefff

Browse files
committed
Add documentation for swift playgrounds integration
Issue: #1971
1 parent 7cd3364 commit ecaefff

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Playgrounds
2+
3+
@Metadata {
4+
@Available("Swift", introduced: "6.3")
5+
}
6+
7+
Interact with the #Playground macro usages in your project.
8+
9+
10+
The Swift Package Manager provides a `swift play` subcommand, which compiles the various playgrounds for your Swift package that are defined using the #Playground macro. Using this subcommand, you can list all the playgrounds in your project or specify one playground to run.
11+
12+
```
13+
$ swift play --list
14+
Build of product 'MyPlaygroundsLibrary__Playgrounds' complete! (2.88s)
15+
Found 2 Playgrounds
16+
* MyPlaygroundsLibrary/MyPlaygroundsLibrary.swift:10 foo
17+
* MyPlaygroundsLibrary/MyPlaygroundsLibrary.swift:21 bar
18+
```
19+
20+
```
21+
$ swift play bar
22+
```
23+
24+
This workflow of finding and running playgrounds for your Swift package has been simplified by the Swift Extension for VS Code. First, all the playgrounds for the workspace are listed under the <doc:project-view>:
25+
26+
![Playgrounds for the workspace listed in the project view.](playgrounds-project-panel.png)
27+
28+
Each listed playground will be labelled with the optional name, or using the unique ID if the playground is unnamed. Clicking on one of the playgrounds will open an editor and highlght where the playground is defined:
29+
30+
![Playground opened and highlighted in the editor.](playground-clicked.png)
31+
32+
You can also press the play button for each listed playground to run that playground:
33+
34+
![Playground run from project panel.](project-panel-play.png)
35+
36+
The editor provides clickable CodeLens which provide another means to run the playground:
37+
38+
![Playground run from CodeLens.](playground-codelens.png)
39+
40+
> Note: This set of features are only available when using a Swift toolchain 6.3 or higher.
41+
30.6 KB
Loading
20.7 KB
Loading
57.3 KB
Loading
127 KB
Loading

0 commit comments

Comments
 (0)