It throw fatal error for data in " self.data.selectedData = i", even I try to calling @State for solve, but nothing change.
Main:
cellView:
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) } }