SwiftData Query not updating after data is loaded from iCloud on initial launch

Apparently the @Query property wrapper from SwiftData does not update when data is loaded from CloudKit. The data can be programmatically be accessed but nothing appears in the view.

Steps to reproduce:

  1. Create new Xcode project using the SwiftData storage option.
  2. Provide a default value for the Item Model. That is required so data can be automatically synced by SwiftData.
  3. Enable iCloud -> CloudKit capabilities and choose a container
  4. Enable Background Modes -> Remote notification capability
  5. Add a toolbar button that prints the number of items from @Query like this:
ToolbarItem {
     Button {           
        print(items.count)
      } label: {
          Label("Count", systemImage: "1.circle")
      }
}
  1. Install app on a physical device that can sync to iCloud.
  2. Add some items using the + in the toolbar
  3. Delete app and wait for around a minute
  4. Reinstall app with a debugger attached
  5. Press the 1.circle button in the toolbar. It will print either 0 or the number of items you previously added. When it does not print 0 the data should be visible but it is not. Once you quit and relaunch the app or press the + button again, all of the items appear.

Has anyone else experienced this before? Anything I can do so the data appears / the view reloads once the items are available? I need to update my view once the data has been loaded from iCloud.

I already filed a bug report with id FB14619787.

Answered by DTS Engineer in 798433022

Yeah, this is a known issue and the SwiftData team is actively working on that. You can get the current status by following up with your feedback report, if that matters.

For more details on Feedback Status, please see Understanding the Status of Your Feedback.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Yeah, this is a known issue and the SwiftData team is actively working on that. You can get the current status by following up with your feedback report, if that matters.

For more details on Feedback Status, please see Understanding the Status of Your Feedback.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftData Query not updating after data is loaded from iCloud on initial launch
 
 
Q