Learn how to use a pre-made playground book with the Learn to Code playground. Learn how to use the toolbar and add input in the playground.
- [Instructor] Swift Playgrounds for iPad is a learning platform. Apple provided in Playgrounds for iPad several lesson books and templates you can learn to use Swift. Even if you've been using Swift for a while, these basic lessons may challenge you. To introduce you to input on the iPad Playgrounds, I'm going to show you one of those lessons. When you launch Playgrounds you'll see a list of files you've worked on before stored in iCloud. In the upper left corner of the page there's a button with a large plus and labeled get Playground. Tap the plus.
You'll see four tabs on the bottom. The first contains the three learn to code courses. This is a series of lessons covering most of the fundamentals of coding in Swift. In the next tab, you'll find challenges, shorter lessons with a specific challenge. Among these you'll find hour of code. Tap hour of code and you get a description. Tap get and the Playground file loads.
Once loaded, tap the file to open the Playground. You'll be greeted by an introductory page. This is a special type of page called a cut scene, which is not Swift but HTML. We'll skip the cut scene for now. We'll cover them later in the course. On the top of the scene you'll find two buttons. The one on the far left takes you back to your files. Tap it, and then tap hour of code to go back in.
The one next to the file button is the table of contents menu. Tap it and you'll find the contents for the book. Towards the bottom of the contents, you'll see the loop jumper page, tap that. A new screen appears. If you have your device in landscape, on the left is the code area, on the right is the live view. The project uses SceneKit to create some 3D characters that you can program to move around their world.
You can rotate the world by dragging left and right over the world. You could also change sound features, by tapping background music and sound effects. In lessons like this there will be some directions and a coding area on the left. Tap the new coding area. The lessons in learn to code and hour code are programming puzzles to solve. This one is to collect the five gems following a pattern. If you do a little detective work you'll find that our pattern is to move forward one, turn left, move forward two, collect the gem, then turn right.
You'll notice on the bottom of the iPad there are completion suggestions. Tapping these adds the function of the code. Tap move forward, and the move forward appears. Tap turn left, then tap move forward twice, then collect gem, and finally, turn right. Press the run my code button, and the character whose name is Byte, follows the directions and tries to collect the gem.
Since he doesn't collect all the gems, he looks sad. To collect all the gems, we need a loop. Below turn right, tap a four loop. The loop appears and asks for a numeric input. You could tap a five in here for the five gems you'll collect. Now tap the word for and the loop highlights. Once highlighted, you can drag it to the top. Now drag the closing brace back down to the bottom to enclose the old code.
Tap run my code, and the code runs. If this is too slow for you, tap the gear, and hit run faster. Once done, Byte has a little happy dance. Apple optimized iPad Playgrounds to not need external keyboards. If you have a keyboard you'll find using Playgrounds a lot easier, but you don't need one if you're tight for space.
You'll find there are taps and gestures for every command.
- Comparing iPad and Xcode playgrounds
- Creating and testing Swift classes and code in iPad and Xcode playgrounds
- Prototyping code
- Debugging and testing with Quick Look live views
- Using markup to interactively document code and create educational lessons
- Compiling code into playground books