By Nick Walter for Udemy
Interested in more than just a guide? Check out Nick’s full Swift course.
TABLE OF CONTENTS: CLICK TO JUMP TO A SPECIFIC SECTION
Table of Contents
What is Swift
Variables and Constants
Strings and Ints
Comments and Print
If Statements and Booleans
Welcome! My name is Nick Walter and I’m here to get you up to speed on Swift as quickly and thoroughly as I can. I am a self taught programmer that knows what it feels like to start from nothing. Using videos, I will explain all the key parts of Swift that you will need to start making apps.
Swift is a programming language created by Apple. We can use this programming language to make apps for Apple products. iPhone/iPad apps, Mac apps, and even Apple Watch apps. It’s important to note that this tutorial is focused on teaching you Swift, not on making apps. After going through this tutorial, you will be prepared to start creating your own apps. And if you’d like help with that please check out my iOS 9 app programming class.
Alright, with that, let me explain some of the history of Swift and what it is. It’s time to watch your first video!
In order to use Swift, we need a Mac app from Apple called Xcode. It’s completely free but it is a HUGE download so be ready for that. This tutorial will teach you Swift 2.0 which is still in beta (that just means Apple hasn’t made it officially public). To use this beta version of Swift, we need a beta version of Xcode 7. You can download that here.
Once that behemoth of a file downloads, double click on the file and let the installation begin!
Variables and Constants are one of the most fundamental parts of Swift. All they do is hold some sort of value, like a number of some letters. That may seem a bit odd but I think after watching the video you’ll see why they’re so cool.
In Swift, Strings are way to represent text. And Ints, are a way to represent whole numbers. You may not have realized it but you were working with both Strings and Ints in the previous video. We’ll talk more about it here…
Ahhh comments, they can help you turn your messy nightmarish code into something beautiful and easy to read. Print will provide more help to you as you are making apps but it is a good part of Swift to learn now. Let’s watch!
This is where the fun starts to begin. “If Statements” allow our Swift code to come to life. We can now make decisions on what should happen in our code if certain conditions are met. Booleans are a type that simply say if something is true or false. They video will explain their beauty.
Arrays are a way to store a bunch of values in a list. Maybe you want to keep a list of your top 5 favorite rappers. Maybe you want to make a todo list of all the things you have to do today. Arrays are your best friend for the job.
This is a nice follow up to arrays. “For loops” allow us to run certain code over and over again. This means that you can run certain code for each item in an array. If that doesn’t interest you, you can use for loops to run a certain chunk of code over and over again.
It might take some time to understand the power of dictionaries. A dictionary holds a bunch of values, like an array, but it doesn’t hold them in a particular order. Instead, dictionaries store values and have a “key” attached to them. That way, you can give a dictionary a certain key, and it will give you the value connected to it. Let’s bounce on over to the video.
This is where the party starts getting crazy! Functions allow you to give a name to a check of code, and run that code whenever you want. You can pass information into that function and it will then change how the chuck of code runs. After watching the video you should start to feel very powerful…
Optionals add extra functionality onto any kind of type. This means you can makes Int optionals, String optionals, array optionals, or anything else! They allow you to say whether something is there, or if it is not. If it is not, it is called nil. This one of the more confusing concepts in Swift so watch the video and be sure to play around on your own until you start to get the hang of it.
This is definitely the most challenging part of the tutorial and I have saved it for last. If you’ve ever heard the term “object oriented programming”, it’s referring to using classes in your code. When I first learned about classes I thought “huh, that’s kinda cool I guess”. But I never really grasped why they’re the bomb-digity. Having made apps for the past 4 years, they’re my best friend. With more and more practice, I think you’ll really come to like them.
Congrats! You now know the basics of Swift. When I am programming apps, I use the above concept for over 90% of my code. There are a few more obscure concepts that you may need to learn but that is what google is for. You know enough now to make apps with confidence. If you’d like to keep learning about Swift, I’d recommend checking out Apple’s documentation. If you’d like to start making apps, consider checking out my course on making apps. I co-teach it with my friend Jenna and it’s a blast.