Xcode 11 beta3 SwiftUI EXC_BAD_INSTRUCTION

I get this when traversing a NavigationLink (ex. NavigationButton) in the iOS simulator:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)


Steps to reproduce:

1. List { ForEach { NavigationLink { Text("detail") } } } }

2. Run in simulator

3. Press on any element

4. The table view cell becomes grey and EXC_BAD_INSTRUCTION is generated

Accepted Reply

I'm also getting an error when performing navigation after updating to beta 3. I simply changed NavigationButton to NavigationLink, but I am not unable to add view to the navigation stack. It seems that PresentationLink is working as expected, but I cannot navigate to a List from a parent List using NavigationLink.


EDIT - I was accessing an environment object in multiple views. As soon as I added the environmentObject() modifier to each view that is shown, the crashes stopped happening. I'm not sure if this is intended, but I don't think that I should need to explicitly pass an environment object between views.

Replies

I'm also getting an error when performing navigation after updating to beta 3. I simply changed NavigationButton to NavigationLink, but I am not unable to add view to the navigation stack. It seems that PresentationLink is working as expected, but I cannot navigate to a List from a parent List using NavigationLink.


EDIT - I was accessing an environment object in multiple views. As soon as I added the environmentObject() modifier to each view that is shown, the crashes stopped happening. I'm not sure if this is intended, but I don't think that I should need to explicitly pass an environment object between views.

> As soon as I added the environmentObject() modifier to each view that is shown, the crashes stopped happening.


Same here, and not just for NavigationLink but also for TabbedViews.


I don't think this should be happening either. But at least there is a workaround until this is fixed. Thanks for the tip!

I confirm it works. The tutorial page has been updated using environmentObject() modifier as well.

It's probably a new norm.


@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)

extension View {


/// Supplies a `BindableObject` to a view subhierachy.

///

/// The object can be read by any child by using `EnvironmentObject`.

///

/// - Parameter bindable: the object to store and make available to

/// the view's subhiearchy.

public func environmentObject<B>(_ bindable: B) -> Self.Modified<_EnvironmentKeyWritingModifier<B?>> where B : BindableObject

}

This no longer seems necessary, as of beta 4. The tutorial only uses it once, in SceneDelagate.swift. And also in previews, but nowhere else.