Swift Intro Online

Swift Intro
April 17, 2017
Project: Getting Started with Swift 3 and Xcode 8
Download our Swift Language Playground here. Playgrounds are interactive coding environments that can contain instructions. You can think of it as a textbook you can code in!
Go through the playground and you'll get a great introduction to a bunch of programming concepts in Swift, including:
varvs.let- Types
- Strings
- Optionals
- Arrays
- Dictionaries
- Tuples
- Control flow
- Functions
- Classes and structs
- Initializers
- Type (static) properties
- Protocols
Once you have the Playground opened, go through the material below before you get started.
About Playgrounds
Before you get started, there are a few things you should know about Swift Playgrounds.
What are Playgrounds?
Playgrounds are interactive coding environments that can contain instructions. The code you write gets run every time you make a change and visual output is displayed on the right. This makes it a great way to learn how to code!
Playground interface
There are two main areas you need to worry about in the intro track playgrounds: navigation and the instructional & coding area.
Navigation
You can use this are to navigate directly to another page. The instructional and coding area also has next and previous page buttons at the bottom. If you do not see the navigation area, it can be opened with the button marked
1 in the above screenshot.Instructional & coding area
This is where you'll be doing most of your work. This area allows for nicely formatted instructions and areas to code! Any areas that have line numbers next to them can be used for coding.
Setting up Xcode
There are two things we need to do to make our Xcode and Playground experience better. You should do this as soon as you start your first playground, it only needs to be done once!
Turning on line numbers
- Go to
Xcode > Preferencesin the menu bar.
- Click
Text Editingin the popup. Check the box next to Line Numbers.
Creating a keyboard shortcut
- Click
Key Bindings(it's next toText Editing). - Enter
executein the search bar. - Double-click the white space next to
Execute Playgrounds. - Press and hold the
optionkey then pressr. - Click in the whitespace below.
- Verify the shortcut was added by watching this gif. The shortcut you added should match the gif.
Running code in Playgrounds
By default, Playgrounds will run the code every-time you stop typing. The visualization will restart and be updated with your new code!
Re-running your code manually
If this does not seem to be working, you can re-run it by toggling the play/stop button at the bottom-left of your instructional & coding area. 

Slower computers
The auto-run feature might not work well on slower computers. You can turn it off by clicking and holding on the play/stop button then selecting 
Manually Run. 
Now you can run your code when you are ready! By following the steps above or holding the
option key and pressing r (this will only work if you setup the keyboard shortcut above).My code is not working!
Playgrounds use a few different symbols to notify you when you have inputed code that will not work. Don't worry too much about the code in these examples, focus on the symbols presented.
It's good to understand what Xcode is trying to tell. Sometimes the message presented will be enough to help you fix it on your own. Other times it will be cryptic and you'll need to ask another student or instructor for help -- it is okay to ask for help!
Error
Errors are a red octagon with a
! inside. Click them to read the message. You must fix the error for your code to finish running!Error with suggestion
Errors with suggestions have a white circle inside instead of an
!. When you double-click them, they pop up a Fix-it suggestion. You can double-click the suggestion and Xcode will try to automatically fix the problem. You must fix the error for your code to finish running!Warning
Warnings do not stop your code from running. They are represented by a yellow triangle. Just like errors, they might have
Fix-it suggestions.
Another thing to note in this example is some warnings and errors will have multiple messages associated with them. See how we click the grey
2 in the example to view both messages?An important note
There is a ton of material in these playgrounds. We do not expect you to memorize it all! Go through each page and complete each challenge. We'll have time for group sessions to clear up any confusion and provide context for confusing concepts. If you can complete the challenges, you can move on to the next concept!
You'll have more practice with each of these concepts throughout the course. A lot of times, these concepts make more sense when you can see them in-action in the context of a real app or game! So don't worry, work through the playgrounds and be comfortable with the fact that you might not memorize everything the first time through. Read carefully, complete the challenges, and you'll do just fine!





Comments
Post a Comment