I have an enum something like...

```
enum MyEnum {
    case a(Foo)
    case b
    case c(Bar)

    enum Foo: String {
        case one
        case two
    }

    enum Bar: String {
        case three
        case four
    }
}

```

I'm trying to create a fail-able initialiser function for this so that you can call it like...

```
MyEnum(base: "a", parameter: "one")

```

or

```
MyEnum(base: "b", parameter: nil)

```

I've got it working (but it's clunky) like this...

```
init?(base: String, parameter: String?) {
    switch (base, parameter) {
    case ("a", let p?) where Foo(rawValue: p) != nil:
        self = .a(Foo(rawValue: p)!)
    case ("b", _):
        self = .b
    case ("c", let p?) where Bar(rawValue: p) != nil:
        self = .c(Bar(rawValue: p)!)
    default:
        return nil
    }
}

```

This will switch on the `base` and then check that the next value can be created before entering the case.

However, I have to now create the `Foo` or `Bar` twice and force unwrap the second one.

Is there a way to get the switch case to create the `Foo` or `Bar` and only enter the case if it can be created so that I can just use that one that was created and not have to create a second one?