Run code in a playground book in Swift Playgrounds on iPad
When you’re ready to see the result of your code, you need to run it. If your playground book has a live view, it can reflect the result of running your code. In some playgrounds, you can have result icons appear to the right of your code as it runs, and then tap them to see the value of your result.
If your code has a print statement, you can view its output in the Console by tapping after you run your code.
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 the Swift Playgrounds app on your iPad, tap Run My Code.
If there are instructions on the right side of the screen, they slide down when you tap Run My Code, so you can watch your code run in the live view. When you tap Stop, the instructions slide back up.
To rerun it, tap Run My Code again. (If it’s already running, tap Stop, then tap Run My Code.)
If your code doesn’t run and a red dot appears in it, see If your code contains an error.
Highlight code or change the animation speed
When you run code in a playground book in the Swift Playgrounds app on iPad, you can do any of the following:
Highlight code as it runs: Tap , 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 tapping and then choosing Run Faster or Run Fastest.
To return to the default run speed, tap Run My Code.
See a result after running code
In some playgrounds in the Swift Playgrounds app on your iPad, 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.
You can do any of the following:
To see the value of the result, tap the result icon.
To see the result as you work in the code, tap the result icon, then tap Add Viewer.
To remove the viewer, tap the result icon, then tap Remove Viewer.
To prevent the result from appearing, tap and turn off Enable Results.
View code feedback or suggestions
After you run code in some playground books, a message might appear, giving advice or suggestions on what to do next.
To close the message when you’re finished with it, tap . You can also tap Next (or another button that appears) to move on. You can reopen the message by tapping .
Tip: If appears after you run code, you can tap it to open the Console and see the output from any print statements in your code. If a dot appears on , it indicates that there’s new, unread output in the Console. To close the Console, tap again. (Not all playgrounds show the Console button.)
If your code contains an error
If your playground book code doesn’t run in Swift Playgrounds on your iPad, a red dot appears next to the line of code that has an issue.
Tap 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.