Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Object-Oriented Swift Inheritance Inheritance and Initializers

Can someone explain me the underscore use, please??!

When he override the method of the "discountedPrice" in the parameters he used the underscore, but I didn't get it, please help me!

2 Answers

It's a syntax for opting out of having to use a name for that parameter when calling the method.

So instead of having to write: tshirt.discountedPrice(percentage: 50), you can instead write tshirt.discountedPrice(50).

Aaron Creasey
Aaron Creasey
1,707 Points

Awesome thanks! That makes perfect sense

I explain myself so that it is the OPTIONAL char, whereby we could use function parameter but when we attribute some value to parameter then we doesn't must call parameter

Basically if you prefix the parameter name with an underscore it makes that parameter name optional. If a default value was set then the parameter in it's entirety is optional.