LAST CHANCE: Save 50% on all my Swift books and bundles! >>

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 Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.