Hello!
I am having trouble with a fatal error that says an index is out of range.
I believe this error has something to do with my ForEach loop and passing through the values of the ForEach to retrieve data from an array — I will copy and paste the “suspected” code below.
TabView (selection: $currentActivitiesIndex) {
ForEach(0..<model.activitiesGalleryData.count, id: \.self) { num in
AsyncImage(url: URL(string: model.activitiesGalleryData[num].url)) { asyncImage in
asyncImage
.resizable()
.scaledToFill()
.frame(height: 250)
.clipped()
.overlay(Color.gray.opacity(0.225))
.tag(num)
} placeholder: {
ZStack {
ProgressView()
Color.gray.opacity(0.2)
}
}
}
}
.tabViewStyle(PageTabViewStyle())
.onReceive(timer) { _ in
withAnimation {
if currentActivitiesIndex < model.activitiesGalleryData.count - 1 {
currentActivitiesIndex = currentActivitiesIndex + 1
} else {
currentActivitiesIndex = 0
}
}
}
Does anything there look visibly off? If more context needed, here is the project’s github repo: GitHub - KadenZheng/PhoeniKZ: University High School App. The front hub page is a bit confusing with all the images but click into the folder and everything code-wise is there The code snippet above is from the SwiftUI file “ImageBar” (organized under the “Views” —> “Reusables” —> “Bars” group). Thank you very much for your help!!
Also, here is a screenshot of the error: