This is the core code.
func testLogDeletion() throws {
let todo = Todo(type: .habit)
for _ in 1...10 {
let log = Log(fid: todo.id, title: todo.title, date: .now)
context.insert(log)
}
let logs = context.fetchLogs(fid: todo.id)
XCTAssertEqual(logs.count, 10, "There are already 10 habit logs.")
let fid = todo.id
try! context.delete(model: Log.self, where: #Predicate { $0.fid_ == fid })
let logs1 = context.fetchLogs(fid: todo.id)
XCTAssertEqual(logs1.count, 0, "All 10 habit logs have been deleted.") // ERROR: still 10 logs
}
function context.delete(model: , where:) doesn’t work, and I found that context.delete(log) can work.
When I run my demo on a real device, everything works fine, but I don’t know where the problem lies. Has anyone encountered the same issue?
New contributor
habitism is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.