'WidgetKit - Intents - widget user setting lost after core data update

Working on an app that contains widget settings. The user can select different options like "alpha" or "beta" as shown in the image. The list data are provided by core data and can be modified in the main app. the entries are stored with an uuid so i can easy identifiy the list items.

the problem. let say i select "Alpha" in the widget's setting, the widget loads the settings from "Alpha". All good.

If i now change the entrie "Alpha" in the main app and do an update to core data, the widget pages looses the previeous selected state "Alpha".

It looks like, as soons as an core update update was performed, the settings screen loose the reference.


class IntentHandler: INExtension, SmallWidgetConfigurationIntentHandling, MediumWidgetConfigurationIntentHandling, LargeWidgetConfigurationIntentHandling {
    let userData = UserData()

    func provideFlapOptionsCollection(for intent: SmallWidgetConfigurationIntent, searchTerm: String?, with completion: @escaping (INObjectCollection<FlapObject>?, Error?) -> Void) {
        let data = userData.getUserDataWithPredicate(_type: "small")
        var symbols: [FlapObject] = []
   
        for item in data {
            let ob1 = FlapObject(identifier: item.id, display: item.title)
            ob1.message = item.message
            ob1.flapid = item.id
            symbols.append(ob1)
        }

        let collection = INObjectCollection(items: symbols)
        completion(collection, nil)
    }
}

Is there a way to keep the widget settings persist even i perform an core data update on that entrie? i mean the identifier and title dont even change.

widget settings page 1 selected settings before core data update 2 setting after core data update - lost reference 3



Solution 1:[1]

Solved. Did a new database entry just for the widget list. If there is some changes in the db, that list is not updated, therefore the widget user-selection is not changed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M K