|
I have
Now I need to execute same query in different place of a program - not in SwiftUI view, but in a method in a class:
I looked up sample code in official Core Data documentation, however when I try to execute this I get an error:
Would appreciate any help with fixing that error. My goal is to get data from Core Data from UPD #1: when I use
UPD #2: when I use UPD #3: When using
but |
|
Seems like your |
|
|
|
I guess with |
|
@nemecek-filip thing is I don't need that in SwiftUI, in SwiftUI it works... I need to get data from request in a regular class. |
|
Maybe I need to use same context I passed in to my SwiftUI environment object? But how to declare it in method? |
|
hi, let me answer your question (not so much to diagnose your code). i have a SwiftUI app where i use a class method outside of a View to execute a fetch. it looks like this for a Core Data entity named
this works fine (iOS 13 -- don't yet know how this will work with the new iOS 14 and SwiftUI App structure). feel free to look through my entire project, if you wish, on Github called ShoppingList. hope that helps, DMG |
|
@delawaremathguy, thank you for your post. I moved my method to another class which didn't use my app's Watch Extension in a Target Membership section and everything worked. I wish compiler said something like "UIApplication is not avaialbe on watchOS". |
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.