I\'m grinding through Apple\'s App Development with Swift book and I have been having a few issues with the Optionals sections.
I\'m getting stuck accessing a dictionary
Your function can be shortened a hell of a lot by taking advantage of some of the tools that’s Swift gives you. Here, take a look, this does the same thing...
func priceCheck(name: String) -> Double? {
guard let stockAmount = stock[name],
stockAmount > 0,
let price = prices[name] else {
return nil
}
return price
}