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!

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 Swift Enums and Structs Structs and their Methods Struct Methods

Perry Lin
Perry Lin
1,190 Points

Swift Enum: Cannot create a variable

Hi there! I'm unsure why there's an error when trying to create the variable 'item'. Pls assist, thanks!

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

init (description: String) {
    self.description = description

// add the calculateTaxes method here
// it should accept only one parameter named 'percentage' of type Double
func calculateTaxes (percentage: Double) -> Double {
    return (self.amount * (percentage/100))


var item = Expense(description: "Any Description", amount: 100)

2 Answers

Nathan Tallack
Nathan Tallack
22,159 Points

While what you are doing is valid code, one thing the challenge asked you to do was to set the amount on a separate line.

Like this.

var item = Expense(description: "Any Description")
item.amount = 100

They are doing this so that you can comprehend that a stored property can be changed on a variable after it is created. :)