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 Stored Properties

having trouble here!?!?!self me self me self me

struct myExpense { 
 48.     let des: String 
 49.     let amou: Double 
 50.     init(des: String, amou: Double){                                                     
 51.         self.des = des 
 52.         self.amou = 0.0 
 53.     } 
 54. } 

so the question mentions storing two properties so I guess my answer still compiles but didn't meet the specifications of the parameters. maybe you can give me a hint ? I might be able to answer it myself.

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

2 Answers

Keli'i Martin
Keli'i Martin
8,227 Points

So you're on the right track. There is one change you'll want to make in your intializer. Then you need to actually declare an Expense variable outside of the struct and use the initializer to populate the initial values from the challenge.

Hope this helps!

Keli'i Martin
Keli'i Martin
8,227 Points

In fact, you probably don't even need an initalizer to get this working.

Keli'i Martin
Keli'i Martin
8,227 Points

Yes, I just confirmed, the initializer is not necessary to pass this challenge

thats creative, I like it!! here's the beginning of the journey

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

lets change it to

struct ShipCargo {
    let description: String
    let amount: Double
    init(description: String, amount:Double){
        self.description = description
        self.amount = amount
    }
}
let var: String = "wooahho space cowgirl, that amount is double the description. What do you have in there... (blank) they don't pay me enough for this crap should I check it?"
Reed Carson
Reed Carson
8,306 Points

A general tip: it will help you IMMENSELY if you don't use shorthand for naming variables or objects of any kind. I did that at first and it may be easier at the time but when you have to go back and look at your code later it can be impossible to decipher what you meant. Even more so if its a project someone else will have to work on as well.

It will be a big help to name everything clearly even if it means more typing, but that shouldn't be a problem anyway because after you've declared something, autocomplete will finish typing it for you elsewhere.