|
Hi Everyone, I'm trying to get my SwiftUI project to work with Core Data, and to be refactored. I'm using property wrappers for its fetch request. I keep getting this error in the log: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." As far as I know, it's something to do with having multiple @StateObject requests. Is this correct? What am I doing wrong here? I'll try and add my relevant code below. Any help here is greatly appreciated. Alternatively I can send you a link to my GH . my refactoring\modelview file
The file that displays clickable data
View that is used to add data, from sub views.
Specific sub-view
|
|
You can only use Also, you create a
but then you keep creating the same object as an
If
and pass it in when you create the child |
|
Hi @Roosterboy, Thank you for your reply. Just to make sure I understand this, I'd need to use @Published within the refatcoring class. So I'd write it like this:
My worry here is that AcountBackEnd is the file created by coredata. So now I'd need to initilalize that in my refaftoring file, which to be honest is a question mark for me. I still don't know how to properly initialize that, and it's embarassing to write. After this, my views should be using @ObservedObject when referencing to the refactor file. Is this right? I've been looking for days now to find a solution to this, but I keep coming up flat, and with more errors. |
|
Ok - So I think I've got it to a good place. To initialize the calls in my refatcoring file, I just wrote them out like this:
And as far as I know, that's an ok way to initliaze those properties. Again, AccountBackEnd is a the Entity file created by cxore data. Where I'm at now is that whenever I click to add/save a new account, nothing happens. It doesn't crash, it just doesn't connect. |
|
I don't really understand why you are trying to fetch a list of your Nor do I really understand what At any rate, this:
isn't going to do what you presumably want it to do. You are creating those items without associating them with any particular Managed Object Context, so they won't be included in your Core Data store. And by making them It's honestly kind of hard to give any good advice since all we are seeing is chopped up pieces without getting a sense of how they all fit together. |
|
Hey - I agree thast I'm probably not making the most sense, but I'm still trying to learn. For what that's worth. I'll try to post again with the headers attached etc. Thanks again for taking the time to reply. EDIT: Just added the headers. :) |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.