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 trialali aboutaleb
4,025 PointsCant fix the mistake that passan made! CAN ANYONE HELP??
I guess that i need to type cast something because the error i have is " Cannot convert value of type 'UILabel!' to expected argument type 'Double?'"
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
updateCell(having: indexPath, selected: true)
quantityStepper.value = 1
updateDisplaywith(totalPrice: 0, itemQuantity: 1)
totalLabel.text = "00.00"
updateDisplaywith(totalPrice: 0, itemQuantity: 1)
currentSelection = vendingMachine.selection[indexPath.row]
if let currentSelection = currentSelection, let item = vendingMachine.item(forSelection: currentSelection) {
let totalPrice = item.price * quantityStepper.value
updateDisplaywith( totalPrice: totalLabel, itemPrice: item.price)
}
}
ali aboutaleb
4,025 PointsThank you steve for responding, i tried what you said and i changed the totalLabel.text to double but it also gave me an error that said "Cannot assign value of type 'Double.Type' to type 'String?'"
1 Answer
Steve Hunter
57,712 PointsHi again,
If you pause the video at 17m26s, you can see that your method isn't quite the same as in the video. I don't know if the rest of your code mirrors the video as I can't see it all.
However, the last line:
updateDisplaywith( totalPrice: totalLabel, itemPrice: item.price)
in the video is:
updateDisplaywith( totalPrice: totalPrice, itemPrice: item.price)
You've defined the totalPrice
constant above this line, so that's fine. So, making that change stops you passing a UILabel
to the method that's expecting a Double
.
I hope that helps,
Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI'm guessing the error is at the
updateDisplayWith
method. You're passing intotalLabel
which is of typeUILabel
but the method is expected a numerical value of typeDouble
. Can you convert thetotalLabel.text
value to aDouble
? It holds a numeric value represented as aString
.Without a link to the video, I can't see what's shown.
Steve.