Skip to content

Console warning presenting alert #5

Description

@rickytribbia

Hi, thank you for sharing this coordinator pattern implementation in SwiftUI using NavigationStack! Awesome.

We're trying to use also .alert(...) functions but this warning appears in console:

Presenting view controller <SwiftUI.PlatformAlertController: 0x116570c00> from detached view controller <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_GS1_GVS_19_ConditionalContentGS2_GS2_GS2_V11MyAppiOS12SplashScreenVS3_19PrerequisitesScreen_GS2_VS3_10PinRequestVS3_11LoginScreen__GS2_GS2_S6_S6__GS2_VS3_14SettingsScreenVS3_19NotificationsScreen___VS3_10HomeScreen_GV12CoordinatorsP10$1063366b017NavigationModiferCS3_14AppCoordinator__VS11_P10$10633652812ModalModifer_GVS_30_EnvironmentKeyWritingModifierGSqGCS11_10NavigationS13______: 0x1077ec500> is not supported, and may result in incorrect safe area insets and a corrupt root presentation. 
Make sure <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_GS1_GVS_19_ConditionalContentGS2_GS2_GS2_V11MyAppiOS12SplashScreenVS3_19PrerequisitesScreen_GS2_VS3_10PinRequestVS3_11LoginScreen__GS2_GS2_S6_S6__GS2_VS3_14SettingsScreenVS3_19NotificationsScreen___VS3_10HomeScreen_GV12CoordinatorsP10$1063366b017NavigationModiferCS3_14AppCoordinator__VS11_P10$10633652812ModalModifer_GVS_30_EnvironmentKeyWritingModifierGSqGCS11_10NavigationS13______: 0x1077ec500> is in the view controller hierarchy before presenting from it. Will become a hard exception in a future release.

Will become a hard exception in a future release. scare me a little bit 😄

We're implementing a simple AppCoordinator which extends NavigationCoordinator with only Screens, for now, without modal ones; so we've implemented enum Screen: ScreenProtocol { ... } and func destination(for screen: Screen) -> some View { ...}.

XCode 16.4
Swift Language Version 5
iOS Deployment Target iOS 16.0

Have you the same warning? What do you think about this?

I've reviewed the effective alert implementation and I agree with this, I would implemented this one in the same way, also after reading this blog post that explains the same way to do it.

If I've understood well your code:

@available(iOS 16.0, *)
@MainActor
public extension NavigationCoordinator {
    
    /// Creates a view for the given screen identifier and applies both navigation and modal capabilities
    func view(for screen: Screen) -> some View {
        destination(for: screen).withNavigation(self).withModal(self)
    }
}

the withModal(self) modifier apply the native SwiftUI .alert(...) method to the NavigationStack created by the withNavigation modifier so I think the implementation is correct.

Any clues? Have we to be worried about the warning?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions