7 Days Swift Challenge – Day 5: Class in Swift and Object Oriented Programming – How to Make an App

[ad_1]
GET THIS SWIFT COURSE FOR FREE:

Today I’ll share with you a new programming paradigm (a way, method, discipline, practice of programming) called Object Oriented Programming.

Your Code Challenge:

+ This is exciting! When we have Object Oriented Programming in our tool belt, we can do a lot more with programming!

+ Let’s create the Flappy Bird character from the silly challenging game 👍

+ We will need to know the location of the bird on the screen so let’s create a class called point (remember to use UpperCamelCase).

+ This class has two properties called x and y of type integer. Initialize their values to be 0 both.

+ Now let’s create another class called flappy bird. Again, don’t forget to use UpperCamelCasing!

+ The first property the bird has is its position which is a variable of type Point! Aha, we can actually have an instance of a class inside another class!

+ Initialize the property called position with Point().

+ Next, let’s have another property called color of type string with the initial value of yellow.

+ Finally, its last property is isWearingHat to know if it’s wearing a hat or not. It’s type if Bool and the initial value is false.

+ Now let’s put these two classes in play. Create an instance of the point class called pos and change its x and y to 10 and 20 respectively.

+ Create an instance (which is an object) of class FlappyBird and make its position to be the pos object we just had in step 8.

+ Change its color to red.

+ Change its isWearingHat to true.

+ Now the bird is moving forward so we need to change its x position to 19.

+ The user just makes the bird fly up, we need to change its y coordinate to 25.

+ This will be a little bit more challenging so please take your time.

+ Please try at least for 2 hours before watching my solution video!

+ Trust me, taking the time to building your programming foundation now will pay off tremendously later.

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

GET THIS SWIFT COURSE FOR FREE:

********************************
*** ABOUT CODE MASTERY ***
********************************
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

*************************
*** MEET DUC TRAN ***
*************************

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.

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


Posted

in

by

Tags:

Comments

2 responses to “7 Days Swift Challenge – Day 5: Class in Swift and Object Oriented Programming – How to Make an App”

  1. Ahsan Karim Avatar

    thanks, your enthusiasm in videos are great 🙂

  2. Earl Alexander Avatar

    it looks like i am back for the classes….

Leave a Reply

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