Skip to Content
Course content

1: Setting Up Xcode and Swift Playgrounds

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Before we write a single line of logic, we have to deal with the tooling. You've likely already hit the App Store and started downloading Xcode. It's a massive download—sometimes a bit of a slog—but it's the only way to fly in the Swift ecosystem. Once it's installed, most beginners make the same mistake: they go to File > New > Project and start building a full-blown iOS app immediately.

The Friction of the Full Project

I’ve seen a lot of junior devs do this because they're eager to see something on a phone screen. But starting with a Project is the "naive" way to learn the language. When you create a project, Xcode generates a mountain of boilerplate. You get an AppDelegate, a ContentView, asset catalogs, and a complex build system that has to compile your entire app every time you want to test a small change.

Imagine you just want to figure out how to filter a list of usernames to find ones that start with the letter "A". In a full project, you'd have to write the logic, trigger a build, wait for the simulator to boot, and perhaps print the result to a console that you're still figuring out how to open. It’s a lot of ceremony for a very simple question. I call this "cognitive overhead"—you're spending more energy fighting the IDE than learning the language.

The Sandbox Approach

The better way, especially for this phase of your journey, is using a Swift Playground. Think of a Playground as a scratchpad. There is no "Build" phase in the traditional sense; you just write code, and the results appear instantly in the sidebar. I use Playgrounds even now, years into my career, whenever I need to prototype a complex algorithm before committing it to a production codebase.

To get one running, go to File > New > Playground and select the "Blank" template for macOS. Now, instead of navigating a file tree, you have a single page. If you want to test that username filter, you just write it and hit the "Play" button next to the line. It’s an iterative loop that takes milliseconds rather than minutes.

var users = ["Alice", "Bob", "Andrew", "Charlie"]
let aUsers = users.filter { $0.hasPrefix("A") }
print(aUsers) // Result appears immediately in the sidebar


When the Sandbox Isn't Enough

Now, you might wonder why we'd ever go back to the "Project" way. The trade-off is that Playgrounds are isolated. They aren't meant for building actual apps that you can ship to the App Store. They don't handle the app lifecycle—like what happens when a user swipes the app away—and they can occasionally be buggy with complex memory management.

But for learning Swift? The speed of the feedback loop is everything. If you spend your first week wrestling with Info.plist files and build targets, you're going to burn out. Stick to the Playground until we start talking about User Interfaces. Once we move into layouts and buttons, we'll migrate your logic into a real project structure.




📋 Practical Task

The Temperature Conversion Sandbox

Your goal is to set up your first Swift Playground and verify that your environment is working by building a simple logic test. Instead of a full app, create a Blank Playground and write a script that converts a list of Celsius temperatures into Fahrenheit.

Requirements:

  • Create a Blank Playground.
  • Define an array of doubles representing Celsius temperatures (e.g., [0.0, 20.0, 37.0, 100.0]).
  • Use a for-in loop or a map function to calculate the Fahrenheit equivalent for each value using the formula: (Celsius * 9/5) + 32.
  • Print the final results to the console.

Verify that you can see the output in the right-hand sidebar (the Debug Area) without having to launch a simulator.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.