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

Errors about structs in swift

The code is attached in the question . The error is:

swift_lint.swift:16:41: error: use of unresolved identifier 'amount'
var item = Expense(description: "Food", amount = 100)
                                                                        ^

Please Help Quickly!!

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

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

    func calculateTaxes(percentage: Double) -> Double {
   return (self.amount * (percentage/100))
  }
}
var item = Expense(description: "Food", amount = 100)
Ian Brennan
Ian Brennan
1,516 Points
var item = Expense(description: "Food", amount: 100)

Just a typo, you need to set the param with : rather than =

Thank You!!!!!! But I still have an error and the output does't show anything

2 Answers

Victor Levytskiy
Victor Levytskiy
7,608 Points
struct Expense {
    var description: String
    var amount: Double = 0.0

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

    func calculateTaxes(percentage: Double) -> Double {
   return (self.amount * (percentage/100))
  }
}
var item = Expense(description: "Food", amount: 100)

As Ian Brennan mentioned all you need is to assign values with the : rather than =

Thank you all!!!