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 Review Structs

Vincent natale
Vincent natale
1,784 Points

I'm not too sure what you are asking me to do here. I have set an init but that is not the same as a default

Error: Variable 'self.description' used before initialized keeps coming up

struct.swift
struct Expense {
    var description : String
    var amount : Double   
  init (){
  amount = 0.0
  }
}

1 Answer

Michael Liendo
Michael Liendo
15,326 Points

Hello there :) You specified two properties in your struct: amount and description. When the struct is initialized, amount has a value of 0.0, but description still has no value. One possible solution would be to simple initialize description in your init method as description = "" where the double quotes represent an empty string.

Hope that helps! Upvotes are always appreciated, and happy coding!