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 trialPedro Ruíz
28,105 PointsAm I missing something or does the simulator have a bug?
init?(fromDictionary dictionary: Dictionary<String,String>) {
guard let initTitle = dictionary["title"], let initAuthor = dictionary["author"] else {
return nil
}
title = initTitle
author = initAuthor
if let initPrice = dictionary["price"], let initPubDate = dictionary["pubDate"] {
price = initPrice
pubDate = initPubDate
}
}
2 Answers
Pedro Ruíz
28,105 PointsThe guard statements have to be written separately for the challenge to accept it as a valid answer.
james white
78,399 PointsDid you try something like:
struct Book {
let title: String
let author: String
let price: String?
let pubDate: String?
init?(dict: [String : String]) {
if dict["title"] == nil {return nil}
if dict["author"] == nil {return nil}
self.title = dict["title"]!
self.author = dict["author"]!
self.price = dict["price"]
self.pubDate = dict["pubDate"]
}
}
..per this thread: