小编dha*_*ydl的帖子

致命错误:UnsafeRawBufferPointer 从 Core Data/NSFetchedResultsController 删除对象时计数为负

这是我第一次使用 AppKit 和NSTableView. 它由NSFetchedResultsController核心数据支持。当数据集发生更改时,Notification将发送:

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
    guard let links = self.fetchedResultsController.fetchedObjects else {
        return
    }

    if self.viewContext.hasChanges {
        try? self.viewContext.save()
    }
        
    self._links = links
    NotificationCenter.default.post(name: .reloadLinkList, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
NotificationCenter.default.publisher(for: .reloadLinkList).receive(on: RunLoop.main).sink { notification in
    self.list.tableView.reloadData()
    self.list.linksModel.selectedRows = IndexSet([])
}
.store(in: &cancellables)
Run Code Online (Sandbox Code Playgroud)

这对于插入和更新数据非常有用。当我尝试删除某些内容时,我得到:

Thread 1: Fatal error: UnsafeRawBufferPointer with negative count
Run Code Online (Sandbox Code Playgroud)

删除选定对象的代码如下:

Thread 1: Fatal error: UnsafeRawBufferPointer with negative count …
Run Code Online (Sandbox Code Playgroud)

macos appkit nsfetchedresultscontroller swift combine

8
推荐指数
1
解决办法
2167
查看次数