7 Days Swift Challenge - Day 6: Class Initializer in Swift - How to Make an App

in #swift7 years ago

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

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.039
BTC 97549.65
ETH 3484.99
USDT 1.00
SBD 3.21