Enter code in Swift Playgrounds on iPad
In the Swift Playgrounds app, you enter code in the coding area on the left side of the screen. The easiest way to add code is to tap a suggestion in the shortcuts bar, below the coding area.
If you want to add code that’s not in the shortcuts bar, you can choose from a list of commonly used code elements.
You can also type code using the keyboard, and even use code that’s in preexisting code modules. See Work with shared files.
Adjust the view
Most playgrounds have a coding area (where you enter code) and a live view, where you run your code to see the result. If you want more room to code, you can hide the live view, or if you only want to see the result, you can hide the coding area.
In a playground in the Swift Playgrounds app on your iPad, touch and hold the resize handle between the coding area and the live view, then drag the handle to expand one or the other to full screen.
Use the shortcuts bar
To see code suggestions based on the code in your playground, tap in the coding area. The shortcuts bar appears below the coding area, showing code suggestions and other controls. You can use the shortcuts bar to quickly insert commands, delete code, or add a new line.
To use the shortcuts bar in the Swift Playgrounds app on your iPad, tap in the coding area to place the insertion point where you want to add code.
Tap a code suggestion in the shortcuts bar.
The code appears in the playground. If the code requires a variable name or value, the keyboard opens.
Use the keyboard to enter the characters you need, then tap to close the keyboard.
See a list of code elements
While you’re coding, you can open a list of commonly used code elements and add them to your code.
In the Swift Playgrounds app on your iPad, tap in the coding area to place the insertion point where you want to add code, then tap near the top right of the coding area.
Tap to see commonly used code elements, then tap a code element to insert it.
Enter characters using the keyboard
You can enter code—including letters, numbers, and special characters—using the keyboard.
In the Swift Playgrounds app on your iPad, tap in the coding area to open the shortcuts bar.
Tap in the shortcuts bar to open the keyboard, then do any of the following:
Add a letter: Tap a letter key.
Add a number or symbol: Swipe down on a letter key until it changes to the number or symbol you want to enter.
For example, if you want to enter the number 5, swipe down on the T key so it changes to a 5.
To instantly bring up the keyboard, double-tap in the coding area.
Use instructions and code examples
Some playgrounds have instructions and code examples on the right side of the screen over the live view. To page through the instructions, swipe through the text or tap the dots or the arrows in the navigation bar at the top.
In the Swift Playgrounds app on your iPad, to use a code example, first touch and hold it until it lifts up, then drag it into your coding area.
As you drag, the insertion point appears in your code where the code example will be inserted.
When the insertion point is where you want the new code, lift your finger.
To try the code example and see what it does, tap Run My Code at the bottom of the live view.
If there are instructions on the right side of the screen, the instructions slide down when you tap Run My Code so you can see the code run. When you tap Stop, the instructions slide back up.
Add images and files
You can add images and files to a playground. For example, if you want to use a custom background image in a coding project, you can use one of the photos from your photo library.
In a playground in the Swift Playgrounds app on your iPad, tap near the top right of the coding area.
Do any of the following:
Add a photo: Tap , then select an image. You can also tap Insert From to select an image from iCloud Drive or the Files app, or tap Photos to select a photo on your iPad.
Add a file: Tap , then select a file. You can also tap Insert From to select a file from iCloud Drive.