7 Days Swift Challenge – Day 2: If Else Statement and Control Flow in Swift – How to Make an App


Today we have two sessions so I hope you will arrange the time to make it happen! Let’s dive right in!

Your Code Challenge:

The magic of modern platforms nowadays whether it’s a social media platform, Netflix to watch movies, Spotify or Apple Music to listen to music, Amazon to buy things is they suggest us things that we might be interested in that we didn’t even consciously aware of!

This really is not magic. It is engineered by a discipline in Computer Science called Machine Learning.

What is Machine Learning?

A major difference between a computer and humans is we humans can learn from past experiences. So the question is, “Can we teach (code) the computer in a way that it can learn from past experiences?”

The answer is yes. That is machine learning — a way we program computers to learn from past experiences — which is data!

For example, if we are Apple’s App Store, looking at our users’ download history, we know what if a person is less than 20 years of age, the person will very much likely want to download Snapchat so we recommend the app to the user. If a user is from 20 to 35 years of age and female, she might like Whatsapp. If a user is from 20 to 35 years of age and male, he might like Instagram. So we recommend those apps to them.

So let’s get into today’s Code Challenge.
+ We will make a simple movie suggestion program. We will need to look at certain movies users watched in the past and suggest new movies.

+ Create an array called movies list containing these movies: The Last Man on The Moon, The Avengers, Captain America, Spider Man Homecoming. What is the type of this array?

+ Next, create an array called suggestion list. Initialize it to be an empty array of String.

+ Now if the movies list array contains The Last Man on the Moon, we will suggest another movie called The Martian by appending the movie to our suggestion list because he might like space exploration movies.

+ If the user watched Spider Man Homecoming, we will suggest Iron Man because they might like hero type of movie — which btw is my favorite

+ If users watched Game of Thrones, we will suggest Sherlock Holmes to them. I never watched GoT but it might fit 😅

+ Finally, share you Code Challenge solution in the comment section with me below!

Have fun, my friends!

– Duc

Love even more advanced and in-depth training with me? Join Total iOS Blueprint 2 where I share with you how to build 11 iOS apps from scratch with awesome video tutorials just like these.


Code Mastery is hosted by Duc Tran, founder of Developers Academy.

This is his free-style no notes, no teleprompter presentation and live coding broadcast with you guys everyday.

To join Duc’s free courses, register for free at


Duc Tran is founder of Developers Academy, one of the world’s leading iOS, Android and Web development trainers.

More than 2,000,000 developers have studied his video trainings; 100,000 developers see his posts each month. Each year, Duc has helped 20,000 plus developers gratudate from his online courses or video series.

To subscribe and get free tutorials, courses and weekly content, visit me at:
Connect with Duc on facebook:
Tweet him:
Get daily inspiration:






2 responses to “7 Days Swift Challenge – Day 2: If Else Statement and Control Flow in Swift – How to Make an App”

  1. Sharpkits Avatar

    Here it is:
    var watchedMoviesList = ["The Last Man on The Moon", "The Avengers", "Captain America", "Spider Man Homecoming","Game Of Thrones"]
    var suggestionList : [String] = [String]()

    if watchedMoviesList.contains("Spider Man Homecoming") {
    suggestionList.append("Iron Man")
    if watchedMoviesList.contains("Game Of Thrones") {
    suggestionList.append("Sherlock Holmes")

  2. Earl Alexander Avatar

    lol i am still going strong must finish everything today just make me coffee after every episode then im cool….

Leave a Reply

Your email address will not be published. Required fields are marked *