Conditional Compilation inside array initializer

Right now, not really. I think I'd go for something like this, which is quite a bit more verbose:

let lol: [String] = {
    var a = [
        "a",
    ]
    #if SOME_CONDITION
    a += ["x"]
    #endif
    a += ["y"]
    return a
}()

In the long run, the next revision of SE-0330 is our best hope.

1 Like