Monday, April 15, 2024
HomeiOS Developmentios - SwiftUI - Setting @State worth causes app to freeze

ios – SwiftUI – Setting @State worth causes app to freeze


I’ve a problem the place the next code causes my app to hold. All of that is wrapped in a navigation stack on the high stage of my app.

struct ParentView: View {
    var physique: some View {
        Checklist {
           Part {
                ForEach(0...5, id: .self) { i in
                    NavigationLink {
                        ChildView()
                    } label: {
                        Textual content("Faucet right here")
                    }  
                }
            }
        }
    }
}

struct ChildView: View {
    @State var viewModel: ChildViewModel
    
    // MARK: - Lifecycle
    init() {
        _viewModel = State(initialValue: ChildViewModel())
    }
    
    var physique: some View {
        Textual content("Whats up, World!")
    }
}

@Observable class ChildViewModel {
    // Empty
}

I’ve remoted it right down to the initialiser of the ChildView class, however cannot work out precisely what’s inflicting it to lock up. If I alter the ChildView class to appear to be this it really works simply positive:

struct ChildView: View {
    // MARK: - Lifecycle
    init() { }
    
    var physique: some View {
        Textual content("Whats up, World!")
    }
}

I’ve tried utilizing State(wrappedValue: viewModel) as nicely, with no luck. I’ve additionally tried profiling the app however it does not appear to really have the ability to decide up the reason for the dangle both.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments