ObservedObject throws EXC_BAD_ACCESS in beta 6

After installing the iPadOS beta 6 on one of my iPads I get an EXC_BAD_ACCESS exception on the first line of the body definition of the root swiftui view.


By placing a breakpoint in that line I can see in the debugger that the value of the ObservedObject passed to the View is set to 0x000000000001.


The Print Description seems to confirm that the observed value has not been correctly initialized:

---------

Printing description of self._model:

expression produced error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated


error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x9).

The process has been returned to the state before expression evaluation.

---------


The same code is still working on an iPad with iPadOS beta 5.

Replies

Same issue here.

I home Xcode beta 6 fixes the issue, but currently every single SwiftUI app is crashing od i(Pad)OS 13 beta 6 and 7 devices.

Bummer.

Same issue here.


Xcode 11.0 beta 5 (11M382q)

watchOS 6.0 (17R5566a)

Yes! Same issue here (Xcode 11 Beta 5, iOS 13 Beta 7, iPhone XR). It took me forever to figure out it was ObservedObject that was causing the crash. Ended up creaing a virtually blank Xcode project to replicate and sure enough adding any ObservedObject to a SwiftUI view causes a crash every time on a real device. I'm working with NFC, so I need to use an actual device rather than the simulator, but obviously have hit a wall.

Fixed in Xcode Beta 6!!!

I am still having the same issue. I am using XCode 11 beta 6, and running the app on a device using iOS 13 beta 7. The app runs on a simulator, not a real device.

I just upgraded to iOS beta 8. No difference. I even copied and pasted example code from Paul Hudson using ObservedObject and it all crashed too, so I know it's not me.


Come on Apple!

As for as I can tell @ObservableObject still does not work in iOS 13 beta 8 using XCode 11 beta 6.

Here is what worked for me:


1. I changed

@ObservedObject var location: MYLocationManager = MYLocationManager()

to:

@EnvironmentObject var location: MYLocationManager

2. In the SceneDelegate I added:

let myLocationManager = MYLocationManager()

and:

window.rootViewController = UIHostingController(rootView: CoreLocationView_NeedsEnv() .environmentObject(myLocationManager)

No more crash!!


I know this is not a solution for @ObservableObject, but it is a workaround until Apple get's it figured out. Thanks to Fabian and greycampbell on SO!

I'm also getting EXC_BAD_ACCESS when I try to have an @ObservedObject property on my SwiftUI View. Xcode 11 beta 7 (which apparently mis-identifies itself as beta 6), and macOS 10.15 Catalina beta 7.


Makes my entire SwiftUI experiment pointless. Guess I'll wait another few weeks.

I have crashing only in the canvas, but I was able to fix it by passing the object in the at the scene delegate but also need to pass it in preview.


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
        .environmentObject(UserModel())
    }
}
SOLVED! I had the same problem.
When using the @Published attribute... seems like you cannot assign a value to the attribute since it is a @property wrapper.
  • Let me explain:

ILLEGAL:
@Published var pairing:[Pairing] = [Pairing]()

LEGAL:
@Published var pairing:[Pairing]
init(){pairing = [Pairing]()}

I hope this helps.