Work with shared files in Swift Playgrounds on iPad
Many playground books have modules that contain shared Swift files. The shared Swift files contain code you can use on any page in your playground. In many playground books, you can also add your own modules and Swift files.
View modules and shared files
If a playground book has modules and shared Swift files, you can view them in the left sidebar.
Open a playground in the Swift Playgrounds app on your iPad, then tap near the top left to open the sidebar.
The modules appear below all the pages in the list. Scroll down, if necessary, to see the modules.
The files in each module appear below the module name.
When you tap a Swift file in the list, it opens in a tab. Because each file opens in a separate tab, you can have multiple files open at the same time. You can switch between open files by tapping the tabs.
Add a module
In many playground books, you can add modules.
Note: In playgrounds that are set to limited mode, you can’t add or delete any modules. (In a limited mode playground, the Add button won’t appear next to Source Code when the sidebar list is in Edit mode.)
In a playground book in the Swift Playgrounds app on your iPad, tap to open the sidebar, then do one of the following:
Tap Edit, then tap the Add button next to Source Code. (If the Add button doesn’t appear next to Source Code, it means you can’t add a module to the playground).
Touch and hold Source Code, then tap Add Module.
A new, untitled module appears in the list, and the keyboard opens.
Enter a name for the new module, then tap Return.
Add a file
You can add Swift files to some playground books, including some limited mode playground books.
In an open playground book in the Swift Playgrounds app on your iPad, tap to open the sidebar, then do one of the following:
Tap Edit, tap next to the module you want to add a file to, then tap Add Swift File.
Touch and hold the module you want to add a file to, then tap Add Swift File.
A new, untitled file appears in the list and the keyboard opens.
Enter a name for the new file, then tap Return.
The new file opens in a separate tab. You can tap in the coding area to enter code.
You can have multiple files open at the same time—each file opens in a separate tab. You can switch between open files by tapping the tabs.
Rename a module or shared file
Note: If you rename a module, make sure you update any files that refer to it. Commands that include the old name won’t work as intended.
In the open playground book in the Swift Playgrounds app on your iPad, tap to open the sidebar, then do one of the following:
Tap Edit, tap next to the name you want to change, then tap Rename.
Touch and hold the module or file you want to rename.
The keyboard opens.
Enter a new name, then tap Return.
Delete a module or shared file
WARNING: If you delete a module or shared file, you can’t get it back. The code it contains is removed, and commands in other files that refer to the deleted one no longer work.
In an open playground book in the Swift Playgrounds app on your iPad, tap to open the sidebar, then do one of the following:
Tap Edit, then tap next to the file or module you want to delete.
Touch and hold the module or file you want to delete.
Tap Delete.