My App is getting crashed immediately after navigating to the screen in iOS>16.0
devices by saying
*** Assertion failure in -[_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF020PagingCollectionView _validateScrollingTargetIndexPath:], UICollectionView.m:7339
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to scroll the collection view to an out-of-bounds item (0) when there are only 0 items in section 0. Collection view: <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF020PagingCollectionView: 0x157a3ee00; baseClass = UICollectionView; frame = (0 0; 720.333 393); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x60000275e9d0>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x600002f758e0>; contentOffset: {0, 0}; contentSize: {0, 393}; adjustedContentInset: {0, 0, 0, 0}; layout: <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF012PagingLayout: 0x1555269a0>; dataSource: <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF011Coordinator: 0x600001a63720>>.'
I don't have any idea regarding UICollectionView
. I haven't used it anywhere in the code
Here's the code I am using. Here I am getting data from MyDataViewModel()
struct DataDisplayView: View {
@StateObject private var myDataVM = MyDataViewModel()
var body: some View {
GeometryReader { reader in
TabView {
let data = myDataVM.data.chunked(into: 3)
ForEach(0..<data.count, id: \.self) { data in
Circle()
.fill(Color.orange.opacity(0.3))
.frame(width: 100, height: 100)
}
.rotationEffect(.degrees(-90))
.frame(
width: reader.size.width,
height: reader.size.height
)
}
.frame(
width: reader.size.height,
height: reader.size.width
)
.rotationEffect(.degrees(90), anchor: .topLeading)
.offset(x: reader.size.width)
.tabViewStyle(
PageTabViewStyle(indexDisplayMode: .never)
)
}
.background(Color.black)
.onAppear() {
myDataVM.dataWebServiceCall()
}
}
}
Below is the extension
of an array
to stride
extension Array {
func chunked(into size: Int) -> [[Element]] {
return stride(from: 0, to: count, by: size).map {
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
}
FYI: The above code works fine in iOS<16.0
FYI: In the above code if I use ForEach(0..<12, id: \.self)
instead of ForEach(0..<data.count, id: \.self)
it is working fine.
I am facing this issue in iOS>16.0
and with dynamic(API)
data.