kodeco.com Forums

Video Tutorial: Beginning Swift 2 Part 4: Functions

Learn how to use functions in Swift 2 to group your code together to into a reusable unit .


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3250-beginning-swift-2/lessons/5

After all these years of studying Objective C, Swift, and iOS, someone finally properly explains what appears to be a double use of certain variable names. I never could get the concept down until this video…external vs. internal uses of name-variables. This alone is worth the price of admission. Thank you. You are an awesome instructor.

1 Like

Thanks for the kind words, and I hope you enjoy the rest of the videos & the intermediate series too!

Questions:

01 “I should be storing its return.” (7:40) Does this mean utilizing the return value?
02 Why create the constant restaurantTotal? Why not simply use totalBill?

Hi. So I could clearly understand the meaning of spreading these functions let me know if I’m thinking correctly:

Function: tipPercentageForRating(rating: Int) - returns percentage amount but requires rating

Function: calculateTipOnTotal - returns tip amount (depending on percentage amount) but requires bill amount and percentage amount (which requires rating)

Function: showTipAdvice - does not return anything, but requires tip amount (which requires bill amount, percentage amount and rating). Don’t understand what is the purpose of the showTipAdvice and why it does not need to return any value?

“Why create the constant restaurantTotal? Why not simply use totalBill?”

My thoughts exactly. Why creating a function showTipAdvice that does not return anything just to printout. A bit confusing.

Just a small math point you are not calculating percentages but fractions