Can't use @ObservedObject on real iPhone

后端 未结 2 1049
终归单人心
终归单人心 2020-12-11 07:35

i can\'t get my view to appear when it uses @ObservedObject in it. The app crashed when i try to present it and i get this error:

Thread

相关标签:
2条回答
  • 2020-12-11 08:31

    This isn't a problem with not conforming to ObservableObject. The code you provided works in the canvas and in the simulator, and should also work on the device. I have already come across this issue with iOS 13 Beta 6 in my own project and have spent a lot of time troubleshooting.

    Other things (such as calling self.presentationMode.value.dismiss() to dismiss a modal view) are also currently broken when running projects built with Xcode Beta 5 on devices running iOS 13 Beta 6. There have been issues with previous betas of Xcode not working on newer betas of iOS, and this may be the same issue.

    I would suggest that you wait until Xcode Beta 6 is released to make any significant structural changes to your code, as iOS 13 Beta 6 may have been developed in anticipation of handling changes that will be made in Xcode Beta 6.

    That being said, if you absolutely must make changes to workaround this issue in the meantime, I've found that using @EnvironmentObject instead of @ObservedObject fixes this issue. In your example, that would mean declaring your property like this:

    @EnvironmentObject private var networkManager: NetworkManager
    

    Then, when you create your view, you can pass a NetworkManager as an environment object like this:

    ContentView()
        .environmentObject(NetworkManager())
    
    0 讨论(0)
  • 2020-12-11 08:33

    Update your project using Xcode 11 beta 6. This fixes the issue. I can confirm it with an app I am working on. Finally came out today!

    0 讨论(0)
提交回复
热议问题