Swift Playground For Mac



If you use Swift Playgrounds for Mac, the code completion works even better. You can press ENTER/return to accept the suggestion. Assuming you’ve written the code, you can tap the Run My Code button to see the result. Swift Playgrounds will then execute the code and display the visual result on a separate pane. In a playground in the Swift Playgrounds app on your Mac, expand either the coding area or the live view to full screen by dragging the border between them. Use the shortcuts list To see code suggestions based on the code in your playground, click in the coding area. The code suggestions appear in the shortcuts list below the coding area. Swift Playgrounds can be downloaded for free from the Mac App Store. Apple points out that you can start a project on one platform and continue it on another - so budding programmers working on.

  1. It makes no sense that Swift Playgrounds is exclusively available for iPad, and Xcode is available exclusively for Mac. What a huge barrier to learning it is to lock it behind yet another.
  2. 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.

Swift Playgrounds User Guide

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 click a code suggestion in the shortcuts list below the coding area.

If you want to add code that’s not in the shortcuts list, you can type code or choose from a collection of commonly used code elements.

You can also use sample code that appears in a playground and use code in preexisting code modules.

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 Mac, expand either the coding area or the live view to full screen by dragging the border between them.

Use the shortcuts list

To see code suggestions based on the code in your playground, click in the coding area. The code suggestions appear in the shortcuts list below the coding area. You can click a shortcut to quickly insert it in your code at the cursor.

  1. To use the shortcuts list in the Swift Playgrounds app on your Mac, click in the coding area to place the insertion point where you’d like to add the code.

  2. Click a code suggestion in the shortcuts list.

    The code appears in the playground at the cursor. If the code requires a variable name or value, these are highlighted in your code so you can quickly click and type to replace them.

Note: To compact the shortcuts list to make more room for your code, click .

See a collection of code elements

While you’re coding, you can open a collection of commonly used code elements and add them to your code.

  1. In the Swift Playgrounds app on your Mac, click in the coding area of your playground to place the insertion point where you want to add code, then click near the top right.

  2. Click to see commonly used code elements, then click a code element to insert it.

Use sample code

Some playgrounds (for example, Sonic Workshop) have instructions with sample code on the right side of the screen. To page through the instructions, swipe them right or left.

  • In the Swift Playgrounds app on your Mac, to use sample code, drag it into the coding area. As you drag, the insertion point appears where the sample code is being placed.

    To try the sample code and see what it does, click Run My Code at the bottom of the Live view.

Tip: To hide the instructions so you can see the live view, click in the upper-right corner of the instructions. To reopen the instructions, click .

Add images and files

You can add your own images or files to a playground. For example, if you want to use a custom background image in a coding project, you can use one of your photos from the Photos app.

  1. In a playground in the Swift Playgrounds app on your Mac, click near the top right.

  2. Do any of the following:

    • Add an image: Click , then select an image. You can also click Insert From to select an image from iCloud Drive or the Finder, or click Photo Library to select a photo in your Photos app.

    • Add a file: Click , then select a file. You can also click Insert From to select a file from iCloud Drive or the Finder.

Swift Playgrounds is a revolutionary app for iPad and Mac that helps you learn and explore coding in Swift, the same powerful language used to create world-class apps for the App Store. Engaging lessons and challenges help students learn the core concepts of coding by writing real Swift code in an interactive environment.

Learn and Explore

In Swift Playgrounds, a single line of code can make amazing things happen. You’ll create small programs called “playgrounds” that instantly show the results of the code that you write. Interactive lessons teach key coding concepts, and additional challenges and starting points encourage you to explore code in exciting new ways to build unique creations. And third parties publish playgrounds you can use to control robots, drones, and other hardware accessories with Bluetooth. It’s easy to share your creations with friends, or record and post videos of your playgrounds in action.

Coding Concepts

Swift Playgrounds includes interactive lessons that use puzzles and experimentation to teach the following core coding concepts, and more:

  • Commands
  • Functions
  • Parameters
  • Loops
  • Conditional statements
  • Variables
  • Operators
  • Types
  • Initialization

Real Swift. Real Frameworks.

The Swift programming language was designed to be approachable enough to be your very first programming language. Swift is also incredibly powerful, used by professional developers to create over half a million apps on the App Store. Using Swift Playgrounds, you’ll be coding within minutes. Even as you become more proficient, you’ll never outgrow Swift.

Swift Playgrounds gives you access to key frameworks, such as UIKit, SpriteKit, Bluetooth, and Metal. Your code can directly interact with the iPad or Mac on which it runs. For instance, on iPad your playgrounds respond to touch gestures and interact with hardware, such as the accelerometer, gyroscope, and camera.

Experiment with Code

Sometimes the best way to learn is to explore on your own, and Swift Playgrounds is a great place to let your imagination run wild. In addition to the guided Learn to Code lessons, Swift Playgrounds includes many challenges, with new ones on the horizon, so you can keep coming back to try something new. Some challenges encourage you to play with code to create interesting effects, while others include engrossing puzzles that require all of your coding skills to solve.

Additional starting points included in Swift Playgrounds help you create playgrounds from scratch. With access to thousands of APIs in the iOS and macOS SDKs, you can create amazing playgrounds that explore the web, generate 3D worlds, experiment with physics, and much more.

Many playgrounds let you edit multiple Swift source files and add your own to the included modules to create infinitely powerful programs. Most playground files can be edited, extended, remixed, or completely reinvented. Collaborate with friends or reimagine them on your own.

Built for Touch

Swift Playgrounds for iPad was designed from the ground up for touch, so you can create entire programs with only a few taps on the screen. Unique coding features include:

  • QuickType for code. The Shortcut Bar intelligently presents the most likely next commands or values based on context. It’s easy to write entire lines of code without touching a keyboard.
  • Coding keyboard. When the time comes for typing, enter numbers and symbols commonly used in Swift coding by dragging your finger across a key to select one of the alternate symbols.
  • Touch to edit. Tap a color value to display a color picker or tap an image value to choose a photo from your library. You can even restructure your code by simply dragging a brace to wrap around the surrounding code.
Swift playground mac os

Swift Playgrounds helps you write correct code by identifying mistakes as you type and offering suggestions to help correct the errors.

Powerful on Mac

Swift Playgrounds for Mac adds features that take advantage of the wide screen on Mac, and includes an always-available keyboard. Unique coding features for Mac include:

  • Code suggestions with help. Code suggestions appear with brief help so you can pick exactly the correct code.
  • Keyboard navigation. Press the Esc key to toggle between the editing area and the code suggestion list, so you never have take your fingers off the keyboard.
  • Sidebar. Expand the sidebar to reveal the complete list of pages, and jump anywhere within the playground. In more advanced content, quickly open supporting Swift files in additional editor tabs with a click.

Code editing on Swift Playgrounds for Mac closely matches Xcode, the professional developer tool used to create apps for the App Store. And because both apps are on Mac, you can experiment with ideas in Swift Playgrounds and easily copy that code into Xcode.

Machine

Command Robots, Pilot Drones, and More

Swift Playgrounds includes accessories playgrounds that teach you how to use Swift code to command LEGO MINDSTORMS EV3 robots that you build, use iPad to guide a Sphero SPRK+ robot around the room, pilot a drone from Parrot or Tello, or even teach a MeeBot to dance. Swift Playgrounds includes guided lessons for each accessory, as well as template starting points you can use to write your own programs that control the following devices:

Swift Playground Mac Os X

  • LEGO MINDSTORMS EV3
  • Sphero SPRK+
  • Drones by Parrot and Tello by Ryze
  • MeeBot by Jimu Robots
  • Dash by Wonder Workshop
  • Skoog musical instrument

Because Swift Playgrounds uses real Swift code with access to the Bluetooth radio on iPad and Mac, any developer can create a playground to connect to additional robots and and devices, then share them with the world.

Author Your Own Content with Xcode

What Is Swift Playground

If you’re an experienced developer, you can create incredible playgrounds to share with the next generation.

Swift Playgrounds authoring templates for Xcode can help you create powerful playground book files to publish as a subscription. The interactivity of playgrounds combined with the power of the iOS SDK and Mac Catalyst lets you express your creativity and skills in an entirely new way, create lessons that teach coding concepts, and employ fun, new approaches to content.