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 trialVan Sanders
16,087 PointsNot sure I understand what is being asked of me.
This challenge has be stumped. I'm affraid that the way the question is framed doesn't make it clear to me what specifically I'm tasked with. Of course it makes sense to me abstractly (that I'm to return nil if the data doesn't exist and the invalidKey error if there is no such key), but I wonder if anyone could rephrase the question or nudge me?
I'm a bit embarassed that this has had me at a stand-still for 2 weeks. I think its become the type of thig where a word starts to sound weird if you say it too many times to yourself. I'm thinking too hard about this...
1 Answer
Grant Jason
10,713 PointsHey Van,
The wording can be a little confusing at times, but don't worry it'll make sense with practice.
Your parse function should contain two guard let statements. They need to be separate because they will be throwing two different errors. In the first statement, you need to check if the the dictionary even exists, and in this case the dictionary is called "data"
The second statement should be checking for valid keys, which we saw in past videos. In this case, your dictionary is data, so you're checking for data["someKey"] and if that doesn't exist, throw the second error.
All in all, your parse function should look something like this:
func parse() throws {
guard let data = data else {
throw ParserError.EmptyDictionary
}
guard let key = data["someKey"] else {
throw ParserError.InvalidKey
}
}
Happy Coding!
Van Sanders
16,087 PointsVan Sanders
16,087 PointsThanks very very much! I'll try not to actually read the code sample and use your instructions first!
You're awesome!