UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Getting a Thread 1: Fatal error....NEED Help fixing

Forums > SwiftUI

Thread 1: Fatal error: No ObservableObject of type ClientStore found. A View.environmentObject(_:) for ClientStore may be missing as an ancestor of this view.

2      

@Bnerd  

I guess in preview?

2      

@strych provides very few clues. Still, let's try to solve this!

A View.environmentObject(_:) for ClientStore may be missing as an ancestor of this view.

Views are like LEGO kits. You can build great things from bits and pieces. Kits look great on their own. But you often combine several smaller kits into a larger kit for more stunning presentations. Sometimes, to build your kit, you may need another small bag of pieces from a different kit, an ancestor kit, if you will. Sometimes you can inject new pieces into your View kit, but most times, you'll just be injecting DATA from some other source.

I think this is the error message you are getting. You're asking SwiftUI to build a VIEW, probably with some fields, Text() objects, maybe a Slider() or a few Buttons(). But you're also asking the VIEW to include data from a kit named ClientStore and it seems to be an @Environment object.

But the compiler complains that it can't finish building this kit because it doesn't have the required parts, namely the ClientStore.

2      

If you use your EnvironmentObject in the init of your View: This doesn't work and you must not do that.

Use a method and call the method in .onAppear.

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.