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

I get the same issue.


Any time I install from XCode Beta 5 onto a device running Beta 6, I get a EXC_BAD_ACCESS when using @ObservedObject


This seems like it would hit nearly everyone on the Beta, so this doesn't make sense


It could be that the XCode being on Beta 5 is a sign the releases did not sync up properly for Beta 6 but I do not see any response from Apple that this happens or that there is a fix or workaround.


Apps run as expected in XCode Simulator.


Can anyone else confirm this happens?


Can Apple chime in about this?

I fully agree with your findings. It is a pain.

I have no clue how to solve it actually apart from removing the @ObservableObject attribute, but that kind of kills the joy.

I managed to write a short code example to reproduce the problem:


var sharedModel = {

SimpleModel()

}()


class SimpleModel : ObservableObject {

@Published var bodyText: String = "body text"

}


struct SimpleRootView : View {

@ObservedObject var model: SimpleModel


var body: some View {

Text("Throws EXC_BAD_ACCESS even without accessing the ObservedObject")

//Text(model.bodyText)

}

}


//Replace the following code in the SceneDelegate:

UIHostingController(rootView: SimpleRootView(model: sharedModel))


This code works on XCode 11 beta 5 Simulator, and on an iPadOS 13 beta 5 but thorw a EXC_BAD_ACCESS error on an iPadOS 13 beta 6.


XCode 11 beta 5 is stated to work together with iPadOS beta 6 but I have not found a workaround or a fix for that major breaking error.


Thanks

Riccardo

Apple - any feedback here? This is quite a reproducable problem and also a blocking type of problem. As seen above - it is fairly easy to document and reproduce.

if you confrom to `ObservableObject` manually you can get around this Combine bug.


on your example add `let objectWillChange = PassthroughSubject<Void, Never>()`

remove `@Published`

add ` var bodyText: String = "body text" { willSet{objectWillChange.send() }}


This doesn't really help if you are using Combine elsewhere in the app. But you example will work. 😕


I find that any call to the Published wrapper crashes.

I have not seen a workaround or fix, I have not heard from Apple, has anyone got any formal information on this? Again, I'd think nearly everyone working on the Beta would be playing with Combine and SwiftUI and as far as I can see, we'd all have this same issue.


Anyone know where to go next on this issue?


How to get a word from Apple on it?

I tried your workaround as follows but I still get an EXC_BAD_ACCESS running on the iPadOS 13 beta 6:


var sharedModel = {

SimpleModel()

}()


class SimpleModel : ObservableObject {

let objectWillChange = PassthroughSubject<Void, Never>()


var bodyText: String = "body text" { willSet{ objectWillChange.send() }}

}


struct SimpleRootView : View {

@ObservedObject var model: SimpleModel


var body: some View {

Text("Throws EXC_BAD_ACCESS even without accessing the ObservedObject")

//Text(model.bodyText)

}

}


I missed something?

I am in the same boat as you trying to figure out what the root of the issue really is...


Try this, seems to work for me but, I do not really know or understand what is going on.

I have moved to working in the simulator and really hoping xcode beta 6 comes out with a fix fast!


class SimpleModel : ObservableObject {

let objectWillChange = PassthroughSubject<Void, Never>()


var bodyText: String = "body text" { willSet{ objectWillChange.send() }}

}


struct SimpleRootView : View {

@EnvironmentObject var model: SimpleModel


var body: some View {

Text(model.bodyText))

}

}


//Replace the following code in the SceneDelegate:

UIHostingController().environmentObject(SimpleModel())

that does not seem to work for me, plus, I think we're using the code syntax correctly, this seems to be a bug - I am surprised nobody confirms they can use it ok, or there are not more people here posting about it.


that seems odd for something that I would expect nearly everyone would be running into.

Same here, but I find it interesting that I've got iOS public beta 5. Tried changing @ObservedObject and ObservableObject to @ObjectBinding and BindableObject respectively, but it still didn't work.

Facing the same problem.

hmmm... that only draws the view once tho... it does not update with the model. If you use "Text($model.bodyText.value))" so as to update with model, you once agian run into the bug.

For what it is worth - it does not help upgrading to iOS 13 beta 7 (I am facing the problem on iOS).


'Apple - provide some feedback here...!

I was also seeing this issue in beta 6, and I am still seeing it in beta 7. Commenting out ObservedObject fixes the issue (but, of course, results in values not updating).


You would think this would at least be listed as a known issue in the release notes!


Has anyone filed a bug report? I will create one now!

I also see this in Beta 7 and 6 both, all devices, watch, TV -- ipad and iPhone


But Simulator conteinues to be fine, of course, Beta 5 is the last XCode I see.


I filed a Radar report with Apple but I have not heard and I don't see any Apple folks chime in here.


Seems like the thread would be swamped if this were happening to everyoen and it's hard to see that going for two beta releases in a row with no mention of it.


So, it seems to me that only a subset of us must be experiencing it or something


Can anyone confirm anyone successfully using Beta 6 or Beta 7 on a device?


I have reached out, but get no confirmations thus far.