Run code in Swift Playgrounds on Mac
When you want to see the product of your code, you need to run it. If your playground has a live view, it can reflect the result of your code. In some playgrounds, you can have result icons appear to the right of your code as it runs, and then click them to see the value of your results.
If you want to visualize the flow of your running code or debug it, you can have Swift Playgrounds highlight each line of code as it runs, helping you identify where problems occur.
In Swift Playgrounds app on Mac, click Run My Code (or use the Touch Bar).
To rerun it, click Run My Code again. (If it’s already running, click Stop, then click Run My Code.)
Highlight code or change the animation speed
When you run code in Swift Playgrounds on Mac, you can do any of the following:
Highlight code as it runs: Click , then choose Step Through My Code.
To highlight your code at a slower pace, choose Step Slowly.
Change the animation speed in the live view: On some playground pages, you can run the code faster by clicking , then choosing Run Fastest or Run Faster.
To return to the default run speed, choose Run My Code.
See a result after running code
In some playgrounds on Mac, you can click , then turn on Enable Results to see result icons appear to the right of your code.
The result icon changes based on the type of information in the result. For example, if you assign “Hello, playground” to a string variable and run your code, you see a result icon with “abc” on it. Click the result icon to see the value of the result.
Tip: To see the value of the result in your code after it’s run, click the result icon, then click “Add viewer.” To remove the viewer, click the result icon again, then click “Remove viewer.”
If your code doesn’t run
If your code doesn’t run, a colored dot appears next to the line of code with an issue.
Click the dot to see an explanation of the issue and any suggestions for how to fix it.
To reset your playground after entering and running code, see Reset a playground.