KnowledgeCity

Swift Intermediate: Swift Playgrounds

In this module, we’ll look at Swift Playgrounds.

In this module, we’ll look at Swift Playgrounds. We’ll clarify the differences between Swift Playgrounds and Xcode Playgrounds. You’ll learn what Playgrounds gives you while you code and what benefits and extensibility Playgrounds offer you.

Playgrounds let you build quick code that you can evaluate and test without setting up a complex Xcode project. It’s a great tool to experiment and try out ideas quickly and easily. Swift Playgrounds comes with pre-made examples of fun and interesting projects, ready for your own experimentation and exploration.

You’ll learn about using live preview in Xcode playgrounds and how you can use this to mockup quick representations of your UI without having to start up a full project. You’ll also learn about using rendered markup inside of Playgrounds. These will help you build notes and navigation in your Playground file. This helps when you collaborate with other people or simply remind yourself of things using a more stylized display within your code compared to using inline comments. 

Learning Objectives

  • Understand the differences between Swift and Xcode Playgrounds
  • Identify how live preview works within Playgrounds
  • Recognize how rendered markup improves your Playgrounds

Author: Mark Nair

Duration: 20m · 3 lessons
Level: Intermediate
Language: English

Skills you’ll gain

Apple XcodeSwift (Programming Language)Swift 3DXcodebuild

What You'll Learn

  • Distinguish between Swift Playgrounds and Xcode Playgrounds
  • Build and evaluate quick code without setting up a complex Xcode project
  • Use live preview in Playgrounds to mock up quick representations of your UI
  • Apply rendered markup to build notes and navigation within a Playground file
  • Experiment with the pre-made example projects that ship with Swift Playgrounds

Key Takeaways

  • Playgrounds let you write quick code that you can evaluate and test without setting up a complex Xcode project.
  • Swift Playgrounds comes with pre-made examples of fun and interesting projects ready for experimentation and exploration.
  • Live preview in Xcode Playgrounds lets you mock up quick representations of your UI without starting a full project.
  • Rendered markup helps you build notes and navigation in your Playground file using a more stylized display than inline comments.
  • Rendered markup is useful when collaborating with others or reminding yourself of things within your code.

Frequently Asked Questions

What does this module cover?

This module covers Swift Playgrounds, including the differences between Swift Playgrounds and Xcode Playgrounds, using live preview in Playgrounds, and using rendered markup. The lessons are Playgrounds Overview, Using Live Preview in Playgrounds, and Using Rendered Markup.

What will I learn about live preview?

You will learn how live preview works within Playgrounds and how you can use it to mock up quick representations of your UI without having to start up a full project.

What is rendered markup used for in Playgrounds?

Rendered markup helps you build notes and navigation in your Playground file, providing a more stylized display within your code compared to inline comments, which is useful when collaborating with others or reminding yourself of things.

What skills does this course relate to?

This course relates to Apple Xcode, the Swift programming language, Swift 3D, and Xcodebuild.

Why use Playgrounds instead of a full Xcode project?

Playgrounds let you build quick code that you can evaluate and test without setting up a complex Xcode project, making it a great tool to experiment and try out ideas quickly and easily.

Transcript

Show transcript (free preview lesson)

Transcript of the free preview lesson. Remaining lessons unlock with the full course.

Hello, my name is Mark Nair, and in these lessons, we'll go through an overview of Swift Playgrounds, how we use live preview in Xcode Playgrounds, and how to use rendered markup in Playgrounds. We'll be working with Xcode Playgrounds for most of this course, but there's another tool you can use to practice your Swift skills and actually create your own apps without using Xcode, that's Swift Playgrounds. So you can run Swift Playgrounds on the Mac or the iPad. Let's take a look at how you do it. So I'm on the Mac right now and this is in the App Store. It's Swift Playgrounds. It's free. Learn real coding the fun way. Sounds pretty great. So I'm just gonna grab it and open it. A lot of choices in Swift Playgrounds. And I want to take a peek at just what the playground is itself. So I have these things that are hanging around and I can investigate, and we'll take a peek at some of these here in a minute. But what I like to do is come down at the bottom and just click Playground, My Playground and open that up. So pretty sparse. Click to enter code. Well, let's try something. So a little bit of code. All I like to do is roll a dye, but the dye has 100 slides on it. So I'm going to generate a random number between 1 and 100. And then I'm going to append that to an array called Number Array, and I'm going to print that out. So in Playgrounds, in Swift Playgrounds just some Swift code here. I don't really see the thing I'm used to doing, but if I come down here to this button and run my code, and then I can click this. Well, there it is. There is my array of random values. Okay, looking pretty good. Do this again. Yeah. Now, there's a button next to it. If I click this, I can use this to go the code step by step. Let's try this step through my code. So we can see the arrow and it's highlighting in the code what's going on. So it's gonna take a long time 'cause it's 100, but one at a time, a random number keeps going. Now, I'm not seeing the display change, of course, but it is appending to the array five times, six times. Okay, so far so good. So this runs our Swift code perfectly fine, but let's take a look at some of the other things inside of Playgrounds that might be pretty interesting. I'm gonna take a look at the app button, plus app right here. Open this up. So at the beginning of a SwiftUI app. So here's the preview. Hello world. Here's my app. Looking good. I can change the content inside of the code. Hello there! Changes there. That's good. And it's using an image from the system name. Pretty good. So now I can see that I can start writing my own SwiftUI code or my regular Swift code that SwiftUIs can take and start building my own app inside of Playgrounds. Very handy. This is very, very handy to use. If I'm using an iPad, I'm just on the go. Previously, you couldn't really make your own app. You could just experiment, but now you can. So let's take a look at a few other things that come with Playgrounds, the Swift Playgrounds. There are a few things in here. Learn to code fundamentals, meme creator, nice interesting little things that are pretty fun. What happens is there is a tutorial that works through it with you. So for example, if I select Choose Your Own Story, now, I'll get this kind of template for me and I'll open it up. Now, inside of here, I have this message. You're the author. You're gonna write your own story. Learn more about it. All right, now I'm on this Swift file. It's a SwiftUI view of first chapter, and walking me through the pieces that I need to do to start doing my app. Well, it looks pretty good. There's some information down here about how SwiftUI needs previews and and how the struct works and how it's laying it out inside of this title. But so far pretty good, and then a lot of the other things that it needs over here are already pre-built for us so we don't have to create them from scratch. A lot of things get a little complicated in here, but really for this, you don't have to worry about it. The same thing with animating shapes, for example. Take a peek at this. Let's take a look at some of this. The Heart pulse. If I play this code, there's an animated heart. The heart drawn with CT points, colors, pulsating, step by step in the code to really understand it, but it is Swift code just using this SwiftUI framework. One other piece I wanna show you is this, getting started with apps. Open this up. Well, good. Okay, so it's an understanding of SwiftUI, certain tasks, learning SwiftUI, some easy introductions to what this new framework is. So feel free to experiment and explore it. Use your basic Swift skills to build out. If you're sitting having waffles one day and your iPad's handy and you just wanna type out some code or have an idea, use it for that basic exploration. Use it for testing out different pieces. Playgrounds are very handy to do that. And then also going through some of the other information, there's some augmented reality, little modules, a few other things in audio, some really interesting things. And then there's some subscription things where other people have built things that you could use and learn. You could do the same thing as well. And Apple has a list of interesting tutorials from Worldwide Developers Conference that talks exactly about using Swift Playgrounds to build your own. Then you can give that content to other people who are actually gonna build on top of yours or learn from you. So take a look at it. It's very fun, it's very friendly. And now with your basic Swift skills, you can just hop in and make some amazing things. Now for us, we're gonna go back to Xcode Playgrounds for the rest of the course to really work on our intermediate development features of Swift. Thanks for watching. Stay tuned for the next lesson where I'll show you how to use live previews in Playgrounds.

Learn on the Go

Take your learning anywhere — the KnowledgeCity mobile app lets you watch lessons on the go.