Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Enums and Structs Structs and their Methods Struct Methods

Jack Farr
Jack Farr
7,882 Points

No compiler error, not sure if this function within structure is written correctly.

Hi everyone,

Not sure why this is not what the question is looking for as it has a simple return. Have also tried including percentage in the initialize category.



struct Expense {
    var description: String
    var amount: Double = 0.0

    init (description: String, amount: Double, percentage: Double) {
        self.description = description
        self.amount = amount

  func calculateTaxes (percentage: Double) -> Double {

return(self.amount * (percentage/100))

1 Answer

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,702 Points

Don't modify the init method. Your calculateTaxes function is good, just substitute that into the code they initially gave you.

Think of it this way. The "amount" property doesn't need an initializer, it already comes with a default value (0.0). And "percentage" isn't a property of the expense struct, it's a parameter of one of it's methods, but it needs to get that information from the outside in order to calculate the taxes. (Kind of like, wait until I know what state I'm in to calculate the taxes, because it will vary).