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 Object-Oriented Swift 2.0 Complex Data Structures Creating an Instance


Not sure why this isn't working?

Challenge Task 1 of 1

Struct definitions are simply blueprints and to use them we need to create an instance. I've declared a struct in the editor.

Create an instance of the struct and assign the values "Animal Farm", "George Orwell" and 6.00 to the title, author and price properties respectively.

Assign this instance to a constant named myBook.

/Users/mattconway/Desktop/Screen Shot 2016-01-22 at 4.05.44 PM.png

struct Book {
    let title: String
    let author: String
    let price: Double

// Enter your code below
let myBook = Book(title: Animal Farm, author: George Orwell, price: 6.00)
myBook.title; author; price
William Forbes
William Forbes
21,469 Points

Hi Matt, You need to quotation marks around each of the string properties. I.E. let myBook = Book(title: "Animal Farm")

except for the price obviously as this is a Double and not string

Also, there is no need to call myBook.title; author; price. This can be removed

Let me know if it works.

Actually I had already put quotes in the first two strings. Adding that "myBook.title; author; price" is what messed it up.

1 Answer

Ashleigh Nombre
Ashleigh Nombre
2,308 Points

Delete the last line

your code in the instance needs to have parentheses

let myBook = Book(title: "Animal Farm", author: "George Orwell", price: 6.00)

when calling an instance you must use the type that your inferring which the title: String author: String price: Double which is a decimal be sure to remember this when they ask for instances.