iOS 18.4.1 breaks SwiftUI's DocumentGroup?

In iOS 18.4.1, DocumentGroup contains the DocumentView twice. (this may cause issues with alerts)

To reproduce (iOS 18.4):

  1. In XCode Version 16.3 (16E140), create new project. Choose iOS, "Document App". No need to make code changes.
  2. Compile and run app on iOS 18.4 (simulator or device).
  3. in iOS (sim or device): Tap create document (once the app launched).
  4. in XCode: click "Debug View Hierarchy"
  5. in XCode: rotate the view Hierarch to reveal duplicated Document View hierarchies (2 Document Hosting Controllers), see screenshot.

This probably affects alert view... I get warnings and it does not work properly (used to work ok on previous versions).

Previous versions

To compare with previous versions of iOS, run the same code and procedure on iOS 18.3 for example (see screenshot).

Will report on Feedback assistant as well...

In your bug report, include a test project that reproduces the issue and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.

The Apple "WritingApp" download provided in "Building a document-based app with SwiftUI" is a clear demonstration of this - and yes it is problematic if you use .alert() on StoryView(). Alerts are presented and immediately dismissed with the log / error message indicating an attempt to present an alert when already presenting.

Run the same App on macOS and there is only one DocumentHostingController, and no problem with .alert

Correction: my alerts problem had a different cause. However. the Apple WritingApp sample is still a good example of the scenario described by randomdev.

Further correction - iOS 13.0-15.8 style alerts:

    .alert(isPresented: $showAlert) {
        Alert(title: Text("App Alert"), message: Text(alertMessage))
    }

work fine.

iOS 15.0 onwards style alerts:

    .alert(
        "Alert title",
        isPresented: $showAlert,
        actions: { },
        message: {
            Text(alertMessage)
        })

appear then disappear with the following log message:

Attempt to present <SwiftUI.PlatformAlertController: 0x121019400> on <SwiftUI.UIKitNavigationController: 0x105836a00> (from <TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView: 0x10383be00>) which is already presenting <SwiftUI.PlatformAlertController: 0x106809800>.

I hope this helps.

This appears fixed as of iOS 18.5.

  1. The NavigationStack {} fix is no longer needed to solve duplication of toolbar items.
  2. The duplicate DocumentHostingController has gone
  3. Alerts are working as expected.

Test environment is Apple's WritingApp sample code built with Xcode 16.3 on macOS 15.5 and running live on an iOS 18.5 iPad Pro.

Will test again as soon as Xcode 16.4 is available with an 18.5 simulator.

Thank you!!

Is there a solution for ios 18.4? We have 30k+ users affected and it makes like half of our app unusable.

Report on feedback assistant FB17490117.

iOS 18.4.1 breaks SwiftUI's DocumentGroup?
 
 
Q