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 trialNikita Voloboev
4,816 PointsI am really confused about this exercise, I kind of understand what is being asked but not sure about implementation.
I am not sure what I need to do in the guard let statements in the function body and if I even need to pass the dict parameter into the function as the problem description does not say so.
I would appreciate any help. Thank you. :)
enum ParserError: ErrorType {
case EmptyDictionary
case InvalidKey
}
struct Parser {
var data: [String : String?]?
func parse(dict: [String : String]) throws {
guard let data == nil else {
throw ParserError.EmptyDictionary
}
}
}
let data: [String : String?]? = ["someKey": nil]
let parser = Parser(data: data)
1 Answer
jcorum
71,830 PointsNikita, try this:
func parse() throws {
if data == nil {
throw ParserError.EmptyDictionary
}
if data!["someKey"] == nil {
throw ParserError.InvalidKey
}
}
Note that the parse() function doesn't take any parameters.