Is it possible to put a tuple in an enum with Swift?

Viewed 2210

If I have the following enum:

enum FruitTuple
{
    static let Apple = (shape:"round",colour:"red")
    static let Orange = (shape:"round",colour:"orange")
    static let Banana = (shape:"long",colour:"yellow")
}

Then I have the following function:

static func PrintFruit(fruit:FruitTuple)
{
    let shape:String = fruit.shape
    let colour:String = fruit.colour

    print("Fruit is \(shape) and \(colour)")
}

On the fruit.shape and fruit.colour I get the error:

Value of type 'FruitTuple' has no member 'shape'

Fair enough, so I alter the enum to have a type:

enum FruitTuple:(shape:String, colour:String)
{
    static let Apple = (shape:"round",colour:"red")
    static let Orange = (shape:"round",colour:"orange")
    static let Banana = (shape:"long",colour:"yellow")
}

But then on the enum declaration I get the error:

Inheritance from non-named type '(shape: String, colour: String)'

So, the question is: Is it even possible to have a tuple in an enum and be able to reference it's component parts in such a way? Am I just missing something fundamental here?

1 Answers
Related