iOS Development #2: Swift Playgrounds

iOS Development #2: Swift Playgrounds
Jan Zavrel
Jan Zavrel Follow June 22, 2021
Share:

Let’s start with the fundamentals of Swift programming language. To run Swift, you need to download either Xcode or Swift Playgrounds, both available for free on Mac App Store. Since Xcode is a really heavy full-blown development environment, we will start with considerably less demanding Swift Playgrounds.

Swift Playgrounds on App Store

Go ahead and install it on your Mac. When you open it, you should see an empty list of playgrounds.

Empty list of My Playgrounds

Let’s create a new one by choosing File -> New Blank Playground from the top menu, or via ⌘ N shortcut.

New playground

Now, click into the window and write this code:

print("Hello, world!")

First Swift code

Open the console by clicking the icon at the bottom-right corner:

Console

Finally, run your code by clicking the button next to the Console button:

Running first Swift code

Cool! You’ve just written and run your first Swift code!

Don’t worry if you don’t understand something, I will explain everything introduced in this article in the rest of this series.

Now, let’s play with print() for a bit. Write this below your existing code and notice how it’s printed on the console in the order that matches the order of the code:

print("       1")
print("     2 3")
print("   4 5 6")
print("7 8 9 10")

That’s because Swift code is read from top to bottom.

Follow me on Medium, Twitter, Facebook and YouTube.

Share:
Jan Zavrel
Written by

Jan Zavrel Follow

Developer, Author, Teacher, Evernote Certified Consultant.