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

iOS

Tuples and Enums inside a function Swift 2

Hi

Is it possible to use an enum inside a tuple when returning something inside a function

here is my code I'm getting the error -- Cannot convert return expression of type 'CarpetColors.Type to return type 'CarpetColors'

What am I doing Wrong?

Jennifer Nordell

Thank You

func cost(length: Int, width: Int) -> Int { let area = length * width

return area

}

enum CarpetColors { case Grey case Tan case }

func carpetCostCalculator(length length: Int, width: Int, carpetColor: CarpetColors = .Tan) -> (Int, CarpetColors) {

// Grey Carpet = £1 sqft
// Tan carpet = £2 sqft
// deep Blue Carpet = £4 sqft

let area = cost(length, width: width)

var price: Int

switch carpetColor {
case.Grey: price = area * 1
case.Tan: price = area * 2
case.Blue: price = area * 4

}

return (price, CarpetColors)

}

2 Answers

Hi,

There are two errors in the code above: 1- You missed the last case of enum CarpetColors , you should add the Blue option 2- The return statement should return the variable carpetColor not the enum type CarpetColors so it should be : return (price, carpetColor)

Thanks