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 trialconnor hoare
7,933 PointsI literally am confused y the question and don't have a clue what to do here.
Please assist me what steps I should take and what to change the catch statements to
enum ParserError: Error {
case emptyDictionary
case invalidKey
}
struct Parser {
var data: [String : String?]?
func parse() throws {
guard let data = data else {
throw ParserError.emptyDictionary
}
guard data["somekey"] != nil else {
throw ParserError.invalidKey
}
}
}
let data: [String : String?]? = ["someKey": nil]
do {
let parser = Parser(data: data)
try parser.parse()
} catch ParserError.emptyDictionary {
} catch ParserError.invalidKey {
}
1 Answer
tromben98
13,273 PointsHi! here is the solution to the challenge:
[Moderator redacted]
Michael Hulet
47,913 PointsHey tromben98!
For future reference, it's frowned upon in the Community to post code that can be copied and pasted and just work without any explanation of why it works and why it's the correct answer. As such, I've redacted your code here. If you'd like, feel free to re-post your solution, but be sure to give a thorough explanation of why it works and why it's the correct answer. Thanks for helping out in the Community!
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsYour code as posted passes all 3 steps of the challenge when I paste it in. What is your question, exactly?