Swift Playground For Mac

Hello and welcome to WWDC. Hi everyone and welcome to WWDC. My name is Lizzy and I'm excited to talk about how to create awesome content for Swift Playgrounds on iPad and Mac. We all know Swift Playgrounds as the app that brought Swift coding to iPad, and now, but with Mac Catalyst, the same app is available on Mac too. Your users will get the same experience they've come to know and love on. Like Swift Playgrounds for ‌iPad‌, Swift Playgrounds for Mac is designed to provide exercises and challenges to help users learn the basics of coding. The app requires no coding knowledge to.

Streaming is available in most browsers,
and in the WWDC app.

  • Learn how to create Swift Playgrounds books that work fluidly across both Mac and iPad and help people of all ages explore the fun of coding in Swift. We'll walk you through how to customize content for each platform while considering platform settings, and help you take advantage of them in your playgrounds while still providing a smooth cross-platform experience. For more on Swift Playgrounds, check out 'Build a SwiftUI view in Swift Playgrounds', and try your hand with 'Swan's Quest'.

    Resources

    Related Videos

    WWDC 2020

  • Download

    Hello and welcome to WWDC. Hi everyone and welcome to WWDC. My name is Lizzy and I'm excited to talk about how to create awesome content for Swift Playgrounds on iPad and Mac. We all know Swift Playgrounds as the app that brought Swift coding to iPad, and now, but with Mac Catalyst, the same app is available on Mac too. Your users will get the same experience they've come to know and love on their iPads now customized for the Mac platform.

    In this session we'd like to share some of the ways that you can customize your content, so it's a great experience on both platforms. After that we'll show a demo of a book that behaves differently on Mac and iPad.

    First let's discuss some updates in the Swift Playgrounds user interface.

    There are a few key parts of the Swift Playgrounds app that have been adapted to better fit the Mac platform. One of these areas is code completion.

    On iPad you'll recognize this as the area where you can browse code completion options for your current state. On Mac there's a new expandable area for code completion that can include quick help for each token. These descriptions can be localized which creates a better code completion experience for users in different languages. To add quick help to your token use three forward slashes directly above your declaration. You can also add descriptions to parameters. Here we added a description to the changeTurtleEyes function.

    You'll see this turtle again later on in our demo and in this once Quest series.

    This text will now appear below your token in the expanded code completion view.

    Even if your users won't be on a Mac these descriptions will still be displayed on iPad as well, in the quick help popovers in the sauce editor and over the original code completion bar. Next let's talk about how your content can be adapted to each platform. There are two new optional keys in the playground book document format, supportedDevices and requiredCapabilities.

    You can use these keys to specify what your book requires from the device to run. If the current device doesn't support a book it won't show up in the feed to specify that your document only runs on Mac or iPad, you can use the supportedDevices key. The valid values for this are 'iPad' and 'Mac'. We'll need to add this key to the book level manifest and to the feed JSON file. For example if your book supports both platforms you'll want to add iPad and Mac with the supportedDevices key in the book level manifest.

    Then add the same values to the supportedDevices key in the feed JSON file as well. This book is now available on both platforms. If Mac is removed from the supportedDevices keys then it will no longer be available on that platform. Instead of only supporting a particular device we can require specific capabilities which can make your content available to more users. The values for the required capabilities key can be anything from the UIRequiredDeviceCapabilities keys available to look at on developer.apple.com. This includes things like ARKit, microphone and Wi-Fi which you can use to specify what your book requires. To use this key add RequiredCapabilities and an array of each capability to the book level manifest.

    Then add requiredCapabilities and the same array to the feed JSON file as well. In this example the book requires use of a microphone and ARKit.

    In general it's best to support as many configurations as possible even if some functionality is different between platforms. To do this we can determine if the playground is being compiled for Mac or for iPad by checking the target environment. It's a good idea to go through the language in your book to make sure it makes sense for both platforms. Some things to look out for are uses of click or touch. Generic language like tap or select is recommended instead. Next let's talk about how content can conform to device settings. When building content, it's important to respect the device system settings such as accent color and dark mood. System provided colors like label or assist in background will automatically respond correctly to changes in dark mode and system accent. You can also add your own adaptive colors, by adding them to the books asset catalog. It's important to be aware of the live view safe area constraints when developing cross-platform content.

    These constraints ensure that your content won't be hidden by any controls over the live view. The constraints are different on Mac since there are toolbar buttons over the top right of the Mac live view. You may have code that uses the liveViewSafeAreaGuide property of a playground live view safe area container.

    Now you can just access the safe area using a standard UI layout guide.

    Next I'd like to introduce my teammate Grace who will be showing you a demo.

    Thanks Lizzy. My name is Grace and I'll be walking through a demo of a playground that we've customized to work on both iPad and Mac. I'll open this playground in the Mac app first. You may recognize this turtle from the Swans Quest series. Pretty cute right. The goal of this book is to customize the look of your character. Once you've done that you can save it as an image and use it in the Swans Quest book. The prose here says to try starting with change turtle skin. I'll start by typing that. And code completion shows me quick help for lots of different customization methods.

    Let's look at how that's implemented. The customization methods are in my turtle edits file. The text here preceded by three forward slashes is what I see in the code completion area for this method. I think this is a little vague so let's change this to 'change the turtle's skin color to the color provided'. And once we go back to our main page. That's the text that shows up in the code completion area. So let's add some customization and see what happens. I'll run my code.

    All right. This is a pretty good looking turtle. I can use the UIColor popovers to quickly change up some of the colors. I think I want the lighter area of the shell to be more of a yellow. I'll run my code again. Perfect. I'll go ahead and save this image. Notice the use and prose of tap not click to use in other books. I also see in the prose, it looks like we can play with AR for on an iPad that supports it. I just so happened to have an iPad with me so I want to check that out. Here's my same document on iPad.

    I've got dark mode on so let's make sure it still looks good. OK, hmm, when I run my code I have a pretty garish white background. That's because I set the background color of my drawing to UIColor.white instead of using a system background. Let's try fixing that and run again. OK awesome.

    So now the background matches my theme and if I switch to light mode it'll be white again. I also noticed a new button here. That's because of my color Grid view controller. I have a target environment check. If I'm not running on macOS then show this button. Since Mac doesn't have the required ARKit capabilities, I won't show it there. All right. So if I tap this button I can check out this turtle In AR. There's lots of ways to create great content that works on both iPad and Mac. When you're creating or updating your Swift Playground's content, keeps these things in mind. Check out the UI on both iPad and Mac. You can take advantage of the updated code completion design on Mac by providing quick help in your content.

    Use #if target environment checks to create different experiences on iPad and Mac. If you're content requires things like a AR or the microphone, specify these as required capabilities. If you can only support one device use the supportedDevices key. Lastly respect the platform settings like dark mode, system colors and layout guidelines. And be sure to pay attention to the accessibility experience on all devices that you support. You can download our sample content along with this video and reference the playground documentation online. Also make sure to check out the Swans quest. You

Learn serious code. In a seriously fun way.

Swift Playgrounds is a revolutionary app for iPad and Mac that makes learning Swift interactive and fun. It requires no coding knowledge, so it’s perfect for students just starting out. Solve puzzles to master the basics using Swift — a powerful programming language created by Apple and used by the pros to build today’s most popular apps. Then take on a series of challenges and step up to more advanced playgrounds designed by Apple and other leading developers.

Robots and drones await your commands.
Now you can make robots do incredible things with code you write yourself. Learn to programme connected devices like the Sphero SPRK+, LEGO® MINDSTORMS® EV3 and drones by Parrot, and watch them come alive before your eyes.

Swift Playground For Mac

Real Swift code.
Real simple. Real playful.

Learning to code with Swift Playgrounds is incredibly engaging. The app comes with a complete set of Apple-designed lessons. Play your way through the basics in “Fundamentals of Swift” using real code to guide a character through a 3D world. Then move on to more advanced concepts.

What you see is what you code: Create code on the left side of your screen and instantly see the results on the right — with just a tap.

Conquer levels, puzzles and coding concepts.

Starting with the “Fundamentals of Swift” lesson, you’ll tackle goals using the same code professional developers use every day. As you move along, more advanced concepts come into play. You’ll continually build on what you’ve learnt and create even more complex code.

Swift Playgrounds For Mac Os

Fundamentals of Swift.

You’ll start out by learning the important concepts you need to understand code.

  • Commands

  • Functions

  • Loops

  • Parameters

  • Conditional Code

  • Variables

  • Operators

  • Types

  • Initialisation

  • Bug Fixing

Master the basics,
then step up to more challenges.

Swift

In addition to the built-in library of lessons, Swift Playgrounds includes a collection of extra challenges — with new ones added over time. Go deeper on a topic you’ve already studied or try your hand at something new. You’re not just building fun creations, you’re building your skills too.

A big world of playgrounds from a big community of developers.

Discover dozens of channels with fun new challenges created by leading developers and publishers. Subscribe to your favourites and you’ll receive their latest creations directly in the app. Now there are no bounds to your playgrounds.

A new way to create code.
On the best device for learning.

Easily drag braces around code, wrap existing code in a loop or choose from dozens of drag-and-drop snippets included in Swift Playgrounds — directly from your iPad or Mac. Take full advantage of powerful Multi-Touch, multitasking and split-screen capabilities on iPad. Also, enjoy the view from your Mac. The larger screen makes room for a new sidebar with a complete table of contents and quick access to other Swift files. Just tap, drag or type text and numbers. Then interact with what you’ve created.

QuickType and coding keyboard.

Write an entire line of code with just a tap. With QuickType for code, the Shortcut Bar automatically and intelligently suggests commands as you go. When typing is the best option, iPad has an innovative keyboard designed for coding. Simply touch a key to access multiple characters, then drag to choose the one you want. Experience similar code suggestions on Mac, which comes with even more help to complete your code.

Snippets Library.

Swift Coding For Kids

Quickly drag commonly used pieces of code from the Snippets Library to minimise typing.

Swift for ipad

Touch to edit.

Conveniently drag the boundaries of a statement around existing code.

Help is just a tap away.

If you come across a command that’s hard to understand, simply tap it and hold. A menu of options will appear. Choose the most relevant one and get the answer you need.

Jump-start your creativity with Starting Points.

Use what you’ve learnt to create something brand new. With Starting Points, you can get a head start on more advanced coding, add multiple files to your playground at once and use iPad features such as Multi-Touch interactions, accelerometer and gyroscope. Personalise your project by adding graphics, audio and more. Then easily share with friends, family or the world. Students can also share code with classmates when teachers use Starting Points to create lessons.

Explore your creations in full screen.

Immerse yourself by using the vivid Retina displays of iPad or Mac. Simply tap the centre divider, then drag to view your code or live project on the full screen. You can also customise built-in games like Battleship and Brick Breaker, then immerse yourself by letting them take up the whole screen.

See your code crawl, roll or fly through the sky.

Watch your code spring to life by programming real robots, musical instruments and drones. The Accessories channel is filled with engaging playgrounds that let you configure and control popular educational toys like LEGO® MINDSTORMS® EV3. And that’s just the beginning.

Swift Playground Per Mac

Sphero playgrounds let you guide this spherical robot through tricky courses, accelerate over jumps and change colours.

Dash playgrounds challenge you to make it sing, dance and respond to sensor inputs to react to its environment.

MeeBot playgrounds guide you through coding Jimu Robot Meebot’s six robotic servo motors to make him move in lifelike ways. Or even dance.

Tello EDU playgrounds let you command multiple Tello drones to fly in a swarm, perform flips and other acrobatic movements, and push the limits of your creativity.

Explore robots, drones and many other connected devices that support Swift Playgrounds.

Swift Playgrounds

Comments are closed.