HomeiOS Developmentios - How can I make a closure to adapt to 'AccessibilityRotorContent'?

ios – How can I make a closure to adapt to ‘AccessibilityRotorContent’?


I created a view which shows a stack of playing cards. I’m passing two parameters to it:

  • an array of card information
  • a closure that builds a CardView for every of the playing cards:
struct CardStack: View {
    var playing cards: [Card]
    var content material: (Int, Card) -> CardView

    init(playing cards: [Card], @ViewBuilder content material: @escaping (Int, Card) -> CardView) {
        self.playing cards = playing cards
        self.content material = content material
    }
    
    var physique: some View {
        ZStack {
            ForEach(Array(playing cards.enumerated()), id: .factor.id) { index, card in
                content material(index, card)
            }
        }
    }
}

It really works nice when the closure accommodates simply the CardView, however as quickly as I add any view modifier to the CardView (and I would like so as to add a lot of them), the returned kind of the closure modifications to some View, and I get an error: Can't convert return expression of kind 'some View' to return kind 'CardView'

var deckBody: some View {
    CardStack(playing cards: viewModel.playing cards) { index, card in  // Error: Can't convert return expression of kind 'some View' to return kind 'CardView'
        CardView(card: card)
            .zIndex(Double(index))
    }
}

Then, after I amend CardView to anticipate a closure returning any View as a substitute of the CardView, I get one other error Static methodology 'buildExpression' requires that 'Content material' conform to 'AccessibilityRotorContent':

struct CardStack: View {
    var playing cards: [Card]
    var content material: (Int, Card) -> any View

    init(playing cards: [Card], @ViewBuilder content material: @escaping (Int, Card) -> any View) {
        self.playing cards = playing cards
        self.content material = content material
    }
    
    var physique: some View {
        ZStack {
            ForEach(Array(playing cards.enumerated()), id: .factor.id) { index, card in
                content material(index, card)     // Error: Static methodology 'buildExpression' requires that 'Content material' conform to 'AccessibilityRotorContent'
            }
        }
    }
}

Why ought to I, and the way can I make the closure conform to ‘AccessibilityRotorContent’?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments