In today training, we will have a look at Swift class’ initializer. What is it, why do we need to use it and how can we use it? Let’s dive right in!

Your Code Challenge:

+ Look at the AppStore on your phone, it has tons of apps, right? Seems like each app has all the same properties like name, developer, rating… Let’s create a class for that!

+ Create a new playground and name it 7DSC-Day6-App

+ Create a new class called app – remember UpperCamelCasing?

+ This class has several properties: name, developer, rating, category, and price.

+ Create those properties and determine what their data types are.

+ Create an initializer for the class that takes all the required information like name, developer, rating, category and price. Initialize these values to our properties.

+ Now let’s create two new instances from your new App class to test it out and use in the upcoming steps.

+ An app store has tons of apps so let’s create a class called AppStore.

+ This class has only one property which is an array of App.

+ Create its initializer which takes an array of apps and initialize the value to our property.

+ Now, let’s create a constant called sampleApps and initialize it by constructing a new array with all the elements being the two App instances you have in step 6.

+ Create a new instance of AppStore name it appleAppStore, pass in the sampleApps above.

+ Can you try to access the second app in all the apps of the appleAppStore?

+ Can you try to access developer property of the first app of all the apps in appleAppStore?

+ Try to spend at least 45 minutes on this challenge. And don’t forget that you always got your back in the solution video. Watch it anyway because I’ll share new ideas in the training too.

Have fun, bring the joy and good luck!

– 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: