Wednesday, July 17, 2024
HomeiOS Developmentios - Sort 'any Form' can't conform to 'Form'

ios – Sort ‘any Form’ can’t conform to ‘Form’


I’m attempting to create completely different shapes on a card primarily based on the cardboard kind in Swiftui.

import SwiftUI
let shapes: [any Shape] = [Circle(), Rectangle(), Ellipse()]

struct CardView: View {
    var physique: some View {
        VStack {
            ForEach(0..<shapes.rely) { index in
                applyStyling(on: shapes[index])
            }
        }
    }
    
    func applyStyling(on form: some Form) -> some View {
        form.fill(.yellow)
    }
}

However I get Sort 'any Form' can't conform to 'Form' on applyStyling(on: shapes[index]) line

I perceive that when utilizing any Form it loses the type-specific info on the underlined Form kind, however I assume the identical is being performed within the instance from WWDC Embrace Swift generics at 25:20 timestamp

WWDC video

In actuality, I needed to retailer all of the drawable shapes in an array after which primarily based on the form kind which I can go to the CardView the suitable Form will probably be drawn.

Can somebody information me on how I can obtain this?

PS: I’ve already tried the AnyShape trick however that trick is just too sophisticated and never very elegant so I imagine there must be an easier to attain this or to construction my code otherwise that handles this drawback.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments