When use ScrollView and ForEach looks like the following code :
ScrollView(.horizontal,showsIndicators: false) { HStack { ForEach(self.QUOTES, id: \.self) { qt in Text(qt) } } } Its ok and no problem. But when I want to use any code (like adding a image) in ForEach block like the following code :
ScrollView(.horizontal,showsIndicators: false) { HStack { ForEach(self.QUOTES, id: \.self) { qt in Text(qt) Image(systemName: "a.square.fill") .resizable() .frame(width: 40, height: 40) } } } I get the following error while writing : Unable to infer complex closure return type; add explicit type to disambiguate
TextandImagein some kind of stack? Stack or Hstack? Honestly, and meant with no offense, this is pretty basic SwiftUI. Maybe your HStack is too... outer... in the FroEach. But stat with something more simple≥ Maybe AList. Or maybe aView. Move that into it's own struct. (My choice? aButton. Who cares if it doesn't do anything. Get it laid out like you wish.) As is, you need to eitherGroupyour code or use a stack of some source. But also? As is, your question doesn't help to say which.