Apple released Xcode 7 beta 4 today with some fixes and many improvements of the Swift language. One of them is indirect attribute for enums and its cases.

It gives us possibility to create recursive enums. Let’s take a look on example. It is not possible in Xcode 7 beta 3, and Xcode will tell you that “Recursive value type Tree is not allowed”.

enum Tree<T> {
    case Leaf(T)
    case Branch(left: Tree<T>, right: Tree<T>)
}

With Xcode 7 beta 4 and new indirect attribute you can create such recursive enum.

indirect enum Tree<T> {
    case Leaf(T)
    case Branch(left: Tree<T>, right: Tree<T>)
}

I believe next update will bring ability to use indirect with structs.

Nice, isn’t it?