I'm trying to show Texts from a ForEach loop after doing an if check. Even though I have VStack inside and outside the ForEach, the text objects appear to overlap. I'm exploring other options as filtering the array but don't understand how to apply that to my conditional. Please let me know if there's an easy way to either have the results inside a VStack or filter the data.
struct LikedView: View {
@ObservedObject var users = getUserData()
@ObservedObject var globalCount = GlobalCount()
@ObservedObject var movies = getMoviesData()
@State var likedArray = []
@State var count = 0
var body: some View {
//Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
ZStack{
ForEach(self.users.datas) { alpha in
ForEach(self.movies.datas) { movies in
VStack{
ForEach(alpha.loved, id: .self) { item in
VStack{
if(movies.id == item){
Text(item)
}
}
}
}
}
}
}
.onAppear{
self.users.fetchData()
self.movies.fetchData()
}
}
}
question from:
https://stackoverflow.com/questions/65557573/text-overlaps-on-if-conditional-in-foreach-statement-swiftui 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…