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

Enums and structs step 2 of 2.. I'm having trouble with the answer..

i did var travel = Expense.description = "" and i dont think i can also do var tavel = Expense.amount = 500.00

I'm kind of stuck..

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


}

var travel = Expense.description = "Flight to Cupertino"

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Devin:

From what I can see, what you are trying to do is create an instance of β€œExpense”.

struct Expense {
    var description: String // String type
    var amount: Double // Double type    
}

// Instance 

var travel = Expense(description: "Flight to Cupertino", amount: 250.00)

When creating an instance of a class or struct you have to call it by its name and its parameters. Since structs create their own initializers, you do not have to create one, just simple use its store properties as its parameters, and give them values according to their type.

Hope this helps