Access Core Data From Widget

Hi, I need to access my core data class from a widget. To then use it for calculating when the widget needs to update, and with what data.

I have defined my widget in the main and then its in an Environment, so that I can access it in all the other views:


@main
struct main_appApp: App {

    @StateObject var vm = CoreDataViewModel()

    var body: some Scene {

        WindowGroup {

            Widget_Resa().environmentObject(vm)

        }

    }

}

you need to use App Groups, and store and access your core data in your app group container. start here https://www.avanderlee.com/swift/core-data-app-extension-data-sharing/

Access Core Data From Widget
 
 
Q