Custom Tabbar component issues

I am trying to build some custom tab bar component (such as the one in the picture below) using SwiftUI.
45

I am trying to achieve a syntax close to SwiftUI's standard TabView component:
`struct ContentView: View {

var body: some View {
    CustomTabbedBar {
        FirstPage().toAnyView()
        SecondPage().toAnyView()
    }
}}

Here's my implementation of the CustomTabbedBar:
`struct CustomTabbedBar: View where Content: View {

@State var selectedIndex: Int = 0
private let content: () -> Content
private let options: [String] = ["Colors", "Scenes"]
private var pages: TupleView<(AnyView, AnyView)>

init(@ViewBuilder content: @escaping () -> Content) {
    self.content = content
    
    self.pages = content() as! TupleView<(AnyView, AnyView)>
}

var body: some View {
    VStack {
        TabbedBarHeader(options: options, selectedIdx: $selectedIndex)
        if selectedIndex == 0 {
            pages.value.0
        } else if selectedIndex == 1 {
            pages.value.1
        }
    }
}

Now, the problem is that when I toggle selectedIndex to change pages, I get === AttributeGraph: cycle detected through attribute 38 ===

The strange fact is that when using Text instead of FirstPage or SecondPage inside the CustomTabbedBar closure, everything works.

Do you have any idea on why this happens and/or how to solve this?

Thanks!

Update - It seems like this problem only occurs in Playground. After I imported the same implementation in an Xcode project everything worked fine as expected.