iOS Functions in Swift Adding Power to Functions Default Values

Paul Karim
Paul Karim
3,428 Points

Wouldn't it be easier to simply call the area function as the area argument?

Hey Guys!

Quick question, so in the last video Pasan chose to change the carpetCost func to accept length and width arguments to then call the area func inside the carpetCost func. I was just thinking wouldn't have been easier to just call the area func AS the area argument?

Ex. carpetCost(havingArea: area(length: 20, width: 22), carpetColor: "tan")

Love to hear input on this matter, thanks!

1 Answer

Paul, I see no reason why this would not work. Definitely give it a try! Pasan teaches in a very fathomable way, but with any type of programming, there are always at least two or three ways to complete a task. Sometimes being creative leads to a better solution in the end. Although I am not giving you a direct answer, I hope this idea will help you somewhat Paul!

If you have any further questions, don't hesitate to ask!