Authors: Jerry Ye, Yuying Fan
Reviewers: Anthony Li, Jordan Hochman
Please leave feedback by posting on Ed or contacting the course staff.
Expected Duration: 10-15 minutes of engagement. 1+ hours of installing & updating software if required.
Objectives
- Learn some vocabulary.
- Ensure your Xcode is set up correctly.
- Meet the Playground — a “scratch pad“ to quickly experiment with Swift
Install Xcode and Simulators
- Make sure you are running macOS Sonoma 14.5 or higher. If you are not, update your OS first. This version is
required for the version of Xcode we use.
- We do recommend you update all the way to the latest version of macOS Sonoma - future versions of Xcode will only support this version.
- Make sure you have at least 30-40 GB free on the disk. This is the typical space taken up by Xcode with its dev
dependencies.
- Go to the Mac App Store and install the latest version of Xcode available. If you have Xcode already, make sure it is
at least updated to one of the version 16's.
- Launch Xcode and accept any permission dialogues. You may need to enter your computer password.
- When you are asked to "Select the platforms you would like to develop for," select "iOS". The others are optional for
this class, and you can always download them
later when needed. Again, make sure you have sufficient storage for the additional components.
You can also install Xcode directly from the Apple Developer site, but you will still need to authenticate with your Apple ID.
Here is a video walk-through of the installation. It also covers topics
including connecting your iPhone with Xcode and running apps from Xcode. App 0 only requires the steps listed above.
Note: If you run into any issues throughout the installation step, make sure
you've updated your OS and have enough
storage available to download XCode. The installation takes a long time, so let it sit for at least a few hours before
asking for help.
If you made it this far, your environment should be set up for the semester. Next, we’ll get started with Xcode
playgrounds.
Xcode Playgrounds
“Playground - noun: a place where people can play”
Playgrounds are miniature testing environments for the Swift language. They allow you to quickly try out code and see
results — without making a full app! Some of our tutorials will use Playgrounds.
Do the following:
- Launch Xcode.
- Click on File > New > Playground.
- Pick "iOS" and "Blank" for the template.
- Name the new playground
hw0_lastname_firstname
and save it in an organized place.
Great! You should now see a Playgrounds file with some boilerplate code:
- This is the code editor. Code goes here!
- This is a “status panel” — a feature unique to Playgrounds. When you initialize a variable, it will show you the
value of that variable. This will also show you useful debugging info, like how many times each line of code is run.
This is a feature of Playgrounds that we won't have when developing full apps.
- This is the play button to compile and run code.
- This is the output console — errors and print statements are sent here.
Do the following:
- Erase the line beginning with
var greeting = "Hello...
- Write a comment:
// HW 0
- Make constants for your name, penn id (number), and favorite emoji (replace the <...>):
let name = "<YOUR NAME>"
let pennId = <PENNID>
let emoji = "<YOUR EMOJI>"
- Add a line to print out your constants:
print("Hello World! My name is \(name) and my pennId is \(pennId) \(emoji)")
- Click the play button to compile and run.
Congrats! You just ran your first line of Swift 🎉🎉🎉
DON’T FORGET: Submit hw0_lastname_firstname.playground
by Wednesday, 1/29 @ 11:59 PM to Gradescope (you may need to .zip
your playground file):
Submit on Gradescope →