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 trialWilliam Hartvedt Skogstad
5,857 PointsNeed help
I can't figure out the right way to initialize it in the following task..
We need to add the first chocolate to our box. Create a stored property named caramelDelight. To this dictionary add a key named flavor that stores a value named caramel to the caramelDelight dictionary to initialize it.
struct ChocolateBox {
caramelDelight: String?
flavor: [caramel]
}
2 Answers
Kantimoy Sur
iOS Development with Swift Techdegree Student 22,499 PointsIn your challenge it says to create a property which you create either using a variable or constant i.e. "var caramelDelight"or "let caramelDelight" and it also says to make it a dictionary by adding a key = "flavor" and value = "caramel", so you do var caramelDelight = ["flavor" : "caramel"]. You can also do it explicitly as your were doing but this way , var caramelDelight : [String:String] = ["flavor" : "caramel"] . Remember declare everything in once line because you want to initialize a dictionary, i wrote variable and dictionary separately just to explain you.
Hope it helps !!
Kantimoy Sur
iOS Development with Swift Techdegree Student 22,499 PointsYou are welcome.
William Hartvedt Skogstad
5,857 PointsWilliam Hartvedt Skogstad
5,857 PointsThanks a lot for your help! :)