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 trialharleythomas
16,512 PointsI keep getting a compiler error because the dictionary is immutable.
I think this is happening because the dictionary is a constant, so it cannot be edited. When I change the dictionary to a variable in Xcode, the program runs fine. Unfortunately, Treehouse requires the dictionary to be defined as a constant with no explanation about how to workaround that fact. The video demonstrates the dictionary being created as a variable.
let currencies = ["US":"Dollar","UK":"Pound","JP":"Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
4 Answers
Chris Shaw
26,676 PointsHi Harley,
The challenge never asks for you to remove the key UK from the dictionary but assign it to a constant called ukCurrency
which you can do by using dictionary key UK.
let currencies = ["US":"Dollar","UK":"Pound","JP":"Yen"]
let ukCurrency = currencies["UK"]
Happy coding!
beven nyamande
9,575 Pointslet myDictionary =['key':'value']
//to update the dictionary you use the key to access the value since dictionaries have no index
// hence
myDictionary['key']="new value"
Chris Shaw
26,676 PointsThis is incorrect.
- Single quotes are illegal, double quotes need to be used
- Constants can't be changed once they're set
beven nyamande
9,575 Pointsoh yes you are right thinking in python
Shawn Bolour
2,423 Pointshi Chris i just thought i would give my feedback. I agree with Harley that the video does not prepare you for this challenge. Happy i foumd this thread because ive been trying to figure this out for the last two days thanks
Chris Shaw
26,676 PointsHi Shawn,
As I said above Amit does mention this technique in the video, I would highly recommend you go back and watch it again.
http://teamtreehouse.com/library/swift-basics/collections/what-is-a-dictionary
Shawn Bolour
2,423 PointsWow, I am impressed with the quick response time, Chris. Thank you.
I've watched the video 3 times. it might be clear to you in the video because you are an experienced developer. I am codding for the first time in my life and it was not clear. Trust me I have patience to learn new concepts so I am not just getting frustrated and commenting when something doesn't go my way. This was just my feedback. Maybe I could have listened more carefully in retrospect. Thanks again.
Chris Shaw
26,676 PointsI can understand that as I once used to feel the same way, something simple I did was instead of learning advanced concepts I went back to the basics every now and then to ensure my knowledge of programming was still fresh, in saying that I highly recommend you go through the Introduction to Programming course which uses JavaScript but creates a nice base to work with.
harleythomas
16,512 Pointsharleythomas
16,512 PointsThank you, Chris.
This is particular confusing because 1) This is approach is not discussed in the video even though the removeValueFromKey approach is discussed, and 2) although this concept is discussed in a previous video on arrays, the task associated with that video does ask you to remove the item from the array in order to assign it to the constant. Just some feedback.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsI understand that but 36 seconds in Amit says the following.
Amit also does show you in the video how to select the values at around 4 minutes in.