Learn Swift 5 for Beginners (2019)

by Chris Ching

This up to date guide will teach you the basics of the Swift programming language.

If you’ve ever tried to learn Swift, you’ll know that there are tons of outdated resources floating around the internet because Swift is in its infancy and Apple updates the language so often.

It’s a tremendous effort, but I’ve kept the following tutorials up to date and will continue to do so!

With that said, let’s dive into the lessons!

Psst! Download and print out my trusty Swift Syntax Cheat Sheet.


Lessons


Lesson 1 Variables

1. Variables
In this lesson, you’ll start at the very beginning with variables.

Lesson 2 Data Types

2. Data Types
This lesson will show you some of the common data types you work with when building apps.

Lesson 3 If Statements

3. If Statements
Learn how to write code that can make decisions!

Lesson 4 Switch Statements

4. Switch Statements
Switch statements are another way for your code to make decisions.

Lesson 5 Loops

5. Loops
Sometimes you just need to repeat something. Loops are just for that!

Lesson 6 Loops Part 2

6. Loops Part 2
More on loops…

Lesson 7 Functions

7. Functions
In this lesson, you’ll learn how to organize your code into actionable functions.

Lesson 8 Functions Part 2

8. Functions Part 2
There’s a lot to functions! This lesson goes into more depth.

Lesson 9 Classes

9. Classes
Classes are another way to organize your code. This lesson is a must!

Lesson 11 UIKit

11. UIKit
The UIKit framework provides a lot of reusable code for us!

Lesson 12 Initializers

12. Initializers
Initializers are important to understand along with classes.

Lesson 13 Optionals

13. Optionals
In this lesson, you’ll learn what an optional is.

Lesson 14 Properties

14. Properties
Properties are kind of like variables but in the context of a class.

Lesson 15 Initializers Part 2

15. Initializers Part 2
More on initializers…

Lesson 16 Arrays

16. Arrays
You’re starting to learn about collection types now! Arrays are first.

Lesson 17 Dictionaries

17. Dictionaries
Dictionaries are another collection type.


Challenges

Want to test what you’ve learned? Take a crack at the challenges below!

You may have to review some of the lessons to refresh your memory but I guarantee that completing these challenges will reinforce what you’ve learned in the lessons above.

When you complete all of the challenges, get your name on the Wall of Fame in the next section!

Instructions

Challenge #1: The Lost Animal Challenge
In this challenge, you’ll write a function that searches two arrays to find an animal.

Download the starter code for this challenge

Challenge #2: The Caterpillar Challenge
In this challenge, you’ll implement the missing function code to make this caterpillar go!

Download the starter code for this challenge

Challenge #3: The Library Challenge
In the toughest challenge of this series yet, you’ll complete the class definition to enable searching for books, checking in/out books and also checking for errors too!

Download the starter code for this challenge

Solutions


Wall of Fame

Get your name and Twitter profile mentioned here!

Step 1: Complete the challenges in the Challenges section above.

Step 2: Click the card below to send out the tweet! I’ll see your tweet and I’ll add your name below and a link to your Twitter profile.

I completed all the Learn Swift challenges! Try them here: https://codewithchris.com/learn-swift @CodeWithChrisClick To Tweet

After you complete the challenges, Click to Tweet above and pronounce your victory! I’ll add your name below:


4 Comments

  1. This is the shortest block of code I could come up with for Challenge 1. However, it’s not the least cycles. Looks pretty clean though.

    func isInArrayShortest(animal: String) -> Bool
    {
    return array1.contains(animal) || array2.contains(animal)
    }

    Hope you like it.

    Reply
  2. Hi,
    So I was giving you clean examples. Here is an actual code snip from #2. Gives me error, String does not conform to protocol SequenceType.

    init(greet:String)
    {
    for char in greet
    {
    body.append(char)
    }
    }

    Reply
  3. Hi,
    I’m doing Challenge 2 and getting errors that I believe I should not be getting.

    let funStr = “just messing around”
    let funStrLen = funStr.count – This tells me .count is unavailable for no good reason. no literally it says, for no good reason!

    for char in funStr {} – this tells me String does not conform to protocol SequenceType.

    What’s going on? Why am I getting these errors?

    Thanks,
    Mike LeGault

    Reply

Leave a Comment

641 Shares
Share
Tweet
Pin
Share
Buffer