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 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"