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 Build a Playlist Browser with Swift Building the Music Library and Playlist Models Creating a Data Model

What am I doing wrong here?

Here is the question: "Let’s assume we want to create a model to represent a box of chocolates. The chocolate box will contain dictionary instances that stores information about different kinds of chocolates. To start, create a struct named ChocolateBox." I am not sure what I am doing wrong or if I am completely doing the wrong thing. Thanks!

ChocolateBox.swift
struct ChocolateBox {

let carmelDelight: String = [["flavor": "caramel"]]
}

3 Answers

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points
// First part of challenge just make the struct
struct ChocolateBox {}

// For the second part of challenge you need to add a dictionary (Key Value paring).

struct ChocolateBox {
var caramelDelight = ["flavor": "caramel"]
}

// In your code the syntax was wrong. You told the compiler that you were creating a String
// when you were actually creating a Dictionary. You also had some extra brackets.

let carmelDelight: String = [["flavor": "caramel"]]

Thanks!

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

You don't need to specify a string, and I'm not sure if you need to change it to a variable but you only need one set of brackets, not two.

var carmelDelight = ["flavor": "caramel"]
Kamil Wrobel
Kamil Wrobel
5,546 Points

this works, it just have a typo instead of "carmelDelight", you need to write "caramelDelight"