SwiftData document based on iOS18 shows blank screen

I have some apps using SwiftData document based. They work as expected under iOS17, but not under iOS18:

  • install the app on a iPad 11 pro (first gen) from my MacBook
  • open the app and open an existing fils (perfect under iOS17)
  • it shows a blank, white screen, no data
  • I can create a new document, blank screen, no data

When I open that newly created file on a iOS 17 iPad pro, it works perfect, as expected

The apps were created from scratch under macOS 14.7 with the corresponding Xcode/Swift/UI version. iOS devices under iOS17

Are there any known problems with document based SwiftData-apps under iOS18, are there any changes one has to made?

Thank You so much for any help!

One thing I noticed is that, on iOS 18, auto-save isn't triggered as frequently as before. If you see that the change you make isn't saved correctly, try to save the model context explicitly using ModelContext.save().

Other than that, if you can provide a minimal project that contains only the code relevant to the issue, with detailed steps to reproduce the issue, I'll be interested in taking a closer look.

You can also try with the following sample to see if it reproduces the issue, and if it does, share the detailed steps.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank You so much for answering! Will try the sample and prepare one of my files.

I downloaded the sample file You provided in Your answer, followed the course to get the final sample.

https://developer.apple.com/documentation/swiftui/building-a-document-based-app-using-swiftdata

Test under macOS: Perfect Test under iOS18: won't work, same as with my apps

  • create the document based version of the sample
  • run it under macOS Sonoma, perfect
  • install the sample on the iOS18 device
  • run the sample
  • create a new file

-> blank screen, can't use the sample

Thank You very much for Your help!

blank screen, can't use the sample

This doesn't happen to me. Let me start with sharing the detailed steps I do to hopefully figure out what happens on your side:

  1. Download the sample app, find the project in the End folder, and open it with Xcode 16.2 (16C5032a) on macOS 15.2 (24C101).

  2. Find ContentView.swift in the project and add the code to save the model context immediately after creating a card, as shown at the bottom of this post.

  3. Select the SwiftDataFlashCardSample target, go to the Signing & Capabulities tab and change the team to mine, and then run the app on my iPhone 16 Plus + iOS 18.2.1 (22C161); observe that the app is up with the standard document browser UI that contains a blue "Create Document" button.

  4. Tap the button; observe the a gray rectangle with a "+" button.

  5. Tap the "+" button; observe the a card with the front side being "Sample Front" and the back side being "Sample Back".

  6. Tap the arrow button on the top right; observe a brown "Sample Front" card.

  7. Tap the lower arrow button on the top left to navigate back; observe two rectangles, one with "+" and the other with "Sampel Front".

  8. Tap the the arrow button on the top left to navigate back to the main UI; observe a new "Untitled" item.

  9. Stop running the app with Xcode and launch it again; observe the same UI as the one showing at step 8.

  10. Tap the "Untitled" item; observe the same UI as the one at step 7, which proves the new card is persisted correctly.

Here is the code snippet mentioned at step 2:

struct ContentView: View {
    ...
    var body: some View {
        ....
            } addCard: {
                let newCard = Card(front: "Sample Front", back: "Sample Back")
                modelContext.insert(newCard)
                
                //Add the following code to save the data immediately.
                do {
                    try modelContext.save()
                } catch let error as NSError {
                    print("Unresolved error \(error), \(error.userInfo)")
                }
                //End.
    ...
}

If you don't mind, please try the above steps on the same system versions, and let me know how the app behaves differently on your side.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank You so much for answering!

As mentioned in the opening post, I am on macOS 14.7 and Xcode 15.4. I have an older iPad running iOS 18.2.1 and would like to check if my apps are working under iOS18.x (I can't yet update to Sequoia/Xcode16, but will do that as soon as possible).

I followed Your instructions, changed the code according to Your snippet - but I got still a blank, empty screen, no buttons, nothing after starting the SwiftDataFlashCardSample.

On my Mac, the sample works fine, as You described - but not on the real iPad (iOS18.2.1)

Can it be, that I have to run Sequoia/Xcode16 to use my apps (document based SwiftData)? No way to check using my existing systen (macOS 14.7/Xcode 15.4)?

Thank You very much and kind regards

SwiftData document based on iOS18 shows blank screen
 
 
Q