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 trial
Kami Wang
5,643 PointsI typed the same codes as what in the video "Returning Complex Values", but the "result" value just appears errors.
func carpetCostCalculator(length length: Int, width: Int, carpetColor: String = "tan") -> (price: Int, carpetColor: String) {
// Gray Carpet - $1/sq ft
// Tan Carpet - $2/sq ft
// Deep Carpet - $4/sq ft
let area = calcalateArea(length, width: width)
var price: Int
switch carpetColor {
case "gray":
price = area * 1
case "tan":
price = area * 2
case "blue":
price = area * 4
default:
price = 0
}
return (price, carpetColor)
}
let result = carpetCostCalculator(length: 10, width: 20) // Errors: Ambiguous use of 'carpetCostCalculator(length:width:carpetColor:)'
result.price
result.carpetColor
Kami Wang
5,643 PointsActually it's a spell mistake from the beginning. But it worked in some codes above this part. So I think it's not the reason why my 'result' value has the errors.
Martin Wildfeuer
Courses Plus Student 11,071 PointsI know, I was not referring to the spelling mistake. The problem will most probably be in the code you did not post here, as your code example does not give any warnings in Playgrounds. (Of course, I had to do my own implementation of calcalateArea).
Ambiguous usually means that you have one or more classes implementing the same property/method. That could also be a subclass overriding the method. The compiler is not able to infer from the context on which kind of object you want to call this.
Martin Wildfeuer
Courses Plus Student 11,071 PointsMartin Wildfeuer
Courses Plus Student 11,071 PointsNot sure why you get an error, I can't reproduce it. What is the implementation of
calcalateArea?