I am currently trying to use TabView for carousel view(PageTabViewStyle) with CoreData.
The error doesn't occur, when I add a new page in order like this age.name: 3, page.name: 4, page.name: 5
But the error occurs, if I put a number in the first/middle order like page.name: 2
If I put page.name: 6, then no error and it's also same with Alphabet. b c d e -> put "f", no problem, but put "a" error.
After turn off the app and open the app, then I see the updated(Page added/Page deleted) ContentView anyway.
I guess, TabView has a sorting problem, so I tried to sort the list of CoreData, change LifeCycle to SwiftUI, but the error occurs again and again. I've also tried with Firebase, but the same problem.
Error Message:
"libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete item 1 from section 0 which only contains 1 items before the update'
terminating with uncaught exception of type NSException"
ContentVIew
TabView() {
ForEach(pages, id: \.self) { page in
SubPage(whichPage: page)
}
}
.tabViewStyle(PageTabViewStyle())
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
AddPage
let page = Page(context: self.moc)
page.name = pageName
do {
print("page.name: \(page.name ?? "Unknown")")
try self.moc.save()
} catch {
print(error)
}
SubPage
@FetchRequest(entity: Page.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \Page.name, ascending: true)]
) var pages: FetchedResults<Page>
var whichPage: FetchedResults<Page>.Element
Using VStack or HStack or List instead of TabView works fine without any problem.