Runtime error: precondition failure: attribute failed to set an initial value

Rumbles

I have a view BugSplitView which works fine alone but causes a

precondition failure: attribute failed to set an initial value

error when navigated to in either preview or the simulator.

The view has an upper part (Color) and a lower part (Color) separated by a horizontal button bar and laid out using the GeometeryReader and a split state. When it is the destination of NavigationButton it doesn't show properly in the Preview and reports the assertion above when run in the simulator. Remove the BugButtonBar and it works. Got me stumped! Help.

import SwiftUI

struct BugSplitView: View {
    @State var split : CGFloat = 0.75
    var buttons : [BugButtonBar.Info]{
        [BugButtonBar.Info(title: "title", imageName: "text.insert"){}]
    }
    var body: some View {
        GeometryReader{ g in
            VStack(spacing: 0){
                Color.gray
                    .frame(width: g.size.width, height: (g.size.height) * self.split)
                VStack{
                    BugButtonBar(infos: self.buttons)
                    Color(white: 0.3)
                }
                    .frame(height: (g.size.height) * (1 - self.split))
            }
        }.edgesIgnoringSafeArea(.all)
    }
}


struct BugButtonBar : View{

    struct Info : Identifiable {
        var id = UUID()
        var title : String
        var imageName : String
        var action: () -> Void
    }

    var infos : [Info]
    func color() -> Color{
        Color.black
    }
    var body: some View {
        HStack(){
            Spacer()
            ForEach(self.infos){ info in
                Button(action: info.action){
                    Text(info.title)
                }
                Spacer()
            }
        }
    }
}


struct ShowBugView : View{
    var body : some View{
        NavigationView {
            NavigationLink(destination: BugSplitView()){
                Text("Show Bug")
            }
        }
    }
}


struct BugSplitView_Previews: PreviewProvider {
    static var previews: some View {
        Group{
            BugSplitView()
            ShowBugView()
        }
    }
}
LuLuGaGa

The problem is that your buttons are declared as computed property. To solve the crash declare them like this:

var buttons = [BugButtonBar.Info(title: "title", imageName: "text.insert"){}]

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Set value of specific property by custom attribute

How to set an initial value for @NSManaged property PFObject Subclass?

RabbitMQ PRECONDITION_FAILED - etiqueta de entrega desconhecida

static_assert failed "typex::value" failure while deserialising binary data using boost

Firestore transaction produces console error: FAILED_PRECONDITION: the stored version does not match the required base version

Google Cloud ML FAILED_PRECONDITION

CalDav Client for iCloud: MKCOL fails with 412 precondition failed

Firebase firestore query: "Error: 9 FAILED_PRECONDITION: The query requires an index. You can create it here"

Docker Error response from daemon: OCI runtime create failed

How to set an initial/default value for the array used by <FieldArray/>?

how to set an initial value for an entity attribute in Jhipster JDL?

value of useState not being set on initial render

SwiftUI crashes with "precondition failure: attribute failed to set an initial value: 85"

How to set initial value of ForeignKey dynamically in CreateView?

getting error 'tuple' object has no attribute 'value'

How do I resolve Runtime Error -2147219712 (80040600):` The operation failed

Ouvir a consulta FAILED_PRECONDITION A consulta requer um índice

Runtime error 1004 : paste method of worksheet class failed

Python unit test failure: should raise value error but not

Failure when creating Content Runtime

how to set initial(default) value in dropdownButton?

ERROR: Manifest merger failed: Attribute application @ appComponentFactory value

ReactJS: State is set back to initial value at each update

Docker build error OCI runtime create failed

Error: Type 'TableMetadata' not found | FAILURE: Build failed with an exception

how to set default initial value on nz-autocomplete

Terraform ERROR: Inappropriate value for attribute "requires_compatibilities": set of string required

How to set the initial value of useState with the value of another state set in a useEffect hook?

Precondition check failed

TOP lista

quentelabel

Arquivo