I'd like to create SKSpriteNodes with a WallType
(please see code below), and only if that WallType
is .Corner
pass it a Side
value for its orientation.
The enums have raw values because I need to load them as numbers from a plist and be able to create them randomly.
enum Side: Int {
case Left = 0, Right
}
enum WallType: Int {
case Straight = 0
case Corner(orientation: Side)
}
I get the error: "Enum with raw type cannot have cases with arguments"
Is there a workaround where I can pass the SKSpriteNode a value for its orientation only when its WallType
is .Corner
?
At the moment I'm initialising it with a value for orientation every time, even when it is not necessary because its WallType
is .Straight
.
I guess I could make Side
optional but then I would have to change a lot of other code where I'm using Side
as well.
And then, I'd still have to pass in nil
.
I'd like to initialise the wall like that:
let wall = Wall(ofType type: WallType)
The information about it's orientation should be inside the WallType
, but only if it is .Corner
.
Is there a way to extend WallType
to fit my needs?
The suggestion made in this thread doesn't really seem to apply in my case: Can associated values and raw values coexist in Swift enumeration?
Alternatively, if I decided to take away the raw value from the WallType
enum, how would I go about loading it form a plist?
I hope that makes sense! Thanks for any suggestions!