Navigation Link results in Unable to present. Please file a bug. message

I just upgraded Xcode to version 12.5 this morning. I was building my project for iOS 14.5 (iPhone). When I select on a NavigationLink, the associated view opens and then immediately closes with the message "Unable to present. Please file a bug.". This was working prior to the upgrade on iOS 14.X but now, I'm receiving this error.

Accepted Reply

Take a look here for a work around: https://developer.apple.com/forums/thread/677333

Replies

Take a look here for a work around: https://developer.apple.com/forums/thread/677333
Did you find a solution? Dealing with exact same on macOS after upgrading to Big Sur 11.3. Seems like a Swift framework error. The workaround mentioned did not work for me.


Solution linked by The Cincinnati Kid did not work in my case (iOS 14.6, Xcode 12.5). I'm using navigationLinks with
Code Block
.isDetailLink(false)
(in order to fix a problem of navigationTitle overlapping) and it only pushes the link for the first time... then is unable to present again.

Any help?

Adding a NavigationLink with an empty view didn't work for me. I solved my issue removing all NavigationLinks from the ForEach and using a single one to control the navigation to the detail view, a tap gesture and 2 state variables to keep track on what is being tapped on.

The example broken code and fix can be found at Paul Hudson's site.

https://www.hackingwithswift.com/forums/swiftui/unable-to-present-please-file-a-bug/7901/8237

Below is the complete working version

import SwiftUI

struct NavigationViewOptions {
    enum OptionType { case main, optional }
    typealias Option = (id: UUID, value: String, type: Self.OptionType)
    static var options: [Option] = [
        (UUID(), "Option 1", .main),
        (UUID(), "Option 2", .optional),
        (UUID(), "Option 3", .main),
        (UUID(), "Option 4", .main),
        (UUID(), "Option 5", .optional),
    ]
        
    static func buildView(for option: Option) -> some View {
        switch option.type {
        case .main:
            return Text("Main Option selected\n\(option.value)").font(.title).fontWeight(.bold)
        case .optional:
            return Text("Optional Option selected\n\(option.value)").font(.title3).italic().fontWeight(.medium)
        }
    }
}

struct NavigationViewWorking: View {

    // State variables to leep track of what option has been tapped on and when to navigate to new view
    @State private var selectedOption: NavigationViewOptions.Option = (id:UUID(),"",.main)
    @State private var showDetail: Bool = false
    
    var body: some View {
        NavigationView {
            ScrollView{
                VStack (alignment:.leading) {
                    Text("NAVIGATION FIX FOR:\nUnable to present. Please file a bug.")
                        .padding(.bottom, 40)

                    ForEach(NavigationViewOptions.options, id: \.id) { option in
                        Text(option.value)
                            .font(.title)
                            .padding(.vertical, 10)
                            .foregroundColor(.accentColor) // same color as navigationLink
                            // handle tap on option
                            .onTapGesture {
                                selectedOption = option
                                showDetail = true
                            }
                    }
                    Spacer()
                    NavigationLink("", destination: NavigationViewOptions.buildView(for: selectedOption), isActive: $showDetail)
                        .opacity(0)
                }
                .navigationTitle("Options")
            }
            // INITIAL DETAIL VIEW
            Text("Select option from the left")
        }
    }
}

@hower your solution basically works, but in this way onAppear on destination view it's called just once. I'm downloading detail content in onAppear in the destination view, how this could be handled?