Thread 1: Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(_:) for msgDatas may be missing as an ancestor of this view.

It throw fatal error for data in "  self.data.selectedData = i", even I try to calling @State for solve, but nothing change.

Main:
Code Block
struct Main : View {
   
  @EnvironmentObject var data : msgDatas
  @State var show: Bool = false
   
  var body : some View{
     
    List(msgs){i in
       
      cellView(pic: i.pic, name: i.name, msg: i.msg, time: i.time, msgs: i.msgs).onTapGesture {
         
        self.data.selectedData = i
        self.show.toggle()
      }
    }
  }
}

cellView:

Code Block struct cellView : View {
   
  var pic : String
  var name : String
  var msg : String
  var time : String
  var msgs : String
   
  var body : some View{
     
    HStack(spacing: 15){
       
      Image(pic).resizable().frame(width: 50, height: 50).clipShape(Circle())
       
      VStack(alignment:.leading,spacing: 5){
         
        Text(name)
        Text(msg).lineLimit(2)
      }
       
      Spacer()
       
      VStack(spacing: 10){
         
        Text(time)
        if msgs != ""{
           
          Text(msgs).padding(8).background(Color("bg")).foregroundColor(.white).clipShape(Circle())
        }
        else{
           
          Spacer()
        }
      }
       
    }.padding(9)
  }
}


Replies

Seems your showing code will continue. Please tell us when done.
And please care about the first line of each code.
brother, it is work , when I click the chatcell, it throw error for " self.data.selectedData = i
        self.data.show.toggle()"

when I click the chatcell, it throw error

I really appreciate your effort, but I cannot find any parts using chatCell, so I cannot test click the chatcell.

And when I click cellView in Main, no errors thrown.
It seems the problem exists in somewhere still not shown yet.

This project writen in SwiftUI 1.0, I want to convert to swiftUI 2.0 . it say (
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(:) for msgDatas may be missing as an ancestor of this view.: file SwiftUI, line 0
Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(
:) for msgDatas may be missing as an ancestor of this view.: file SwiftUI, line 0)

This project writen in SwiftUI 1.0, I want to convert to swiftUI 2.0 . it say (

It might be helpful under some different context. But as for now, without enough code to reproduce the issue, I can say just there is something wrong in the hidden parts of your code.
I have tab view inside a navigation view is crashing without any reason.

its working without tab view seems to be bug....

seems to be bug

It may be a bug of SwiftUI, or it may be a bug of your code. You have not shown enough info to judge.
I shown all

I shown all

Not true!!!
Where is the tab view you mentioned? Where is ConentView? Chat? msgdataType? msgTail? Rounded?
Why is there no code using chatCell?!?!?!

Say shown all after you have shown all!!!!!
One more, please do not leave a thread without saying anything.

If you have some reason that you cannot show any more codes, please say so.
Brother as I said u, u are not here for solution, u just ask question

Brother as I said u, u are not here for solution, u just ask question 

I do not understand why you insult me spending plenty of hours finding to solve your issue.
I ask you questions because I need them to solve your issue.
I am sure I can solve your issue when you could show enough info.

I will be watching this thread. When you will show enough info, I will try to help you solve your issue.
Or if you solve it by yourself, please share your solution.
OOPer, I think you are being too nice, and have maybe too much patience. I would stop watching this thread, and if you like helping people here on the forums, spend time with others who respect your time, post code properly, and answer your questions.

OOPer, I think you are being too nice, and have maybe too much patience. I would stop watching this thread, and if you like helping people here on the forums, spend time with others who respect your time, post code properly, and answer your questions. 

Thanks @rnikander. Maybe you are right. I will re-consider how I should spend my time.
@OOPer I am not insult u, I am just fed up question question...I need solution, I respect u whole my hearth.