ios – Core Data database does not reflect changes made from widget extension in the main app


Ok, I simply have Main App and the Widget extension. There is a shared .xcdatamodel file between an app and extension. There is a Setting entity.

@objc(Settings)
class Settings: NSManagedObject, Fetchable {
    @NSManaged var identifier: String
    @NSManaged var createdAt: Date?
}

From within the widget I do an update on Setting entity, for example I change the date:

settings.createdAt = Date() // of course I fetch settings in context and save that context correctly.

And changes are reflected in widget extension. I can see a correct value, but in the app, there is old createdAt date… and there is no way to force it to refresh…

When it works? When I reopen my app (close and open again), then it is reflected correctly, and I can see my latest change also in the main app. Why?

Why it doesnt work without closing the app? How can I refresh, reload, pull changes from widget extension?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img