In my app which uses SwiftUI for interface I have a button that performs an action:
func getBooksCountNumber() -> Int {
var countResult = 0
let booksFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "Book")
do {
let booksFetch = try self.persistentContainer.viewContext.fetch(booksFetch) as! [Book]
countResult = booksFetch.count
print("countResult is \(countResult)")
} catch {
fatalError("Failed to fetch: \(error)")
}
return countResult
}
When I delete rows in the app I use moc.delete(book)
and try? moc.save()
. I see that deleted rows gone, using interface at icloud.developer.apple.com. For example — if from 3 records I delete 1, I still getting 3 in countResult
and not 2. Any help is appreciated.