Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.