- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将数据保存到 CoreData 时出现以下错误。我使这个项目变得非常简单,以便您查看我的项目。项目中有Local json。您可以下载并测试我的项目。
GitLab 项目链接: Core Data Test Project
2021-08-20 20:17:03.576453+0300 CoreDataTest[27924:2275095] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'QuestionCD' so +entity is unable to disambiguate.
CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'QuestionCD' so +entity is unable to disambiguate.
2021-08-20 20:17:03.576623+0300 CoreDataTest[27924:2275095] [error] warning: 'QuestionCD' (0x28090c9a0) from NSManagedObjectModel (0x281d3d400) claims 'QuestionCD'.
CoreData: warning: 'QuestionCD' (0x28090c9a0) from NSManagedObjectModel (0x281d3d400) claims 'QuestionCD'.
2021-08-20 20:17:03.576675+0300 CoreDataTest[27924:2275095] [error] warning: 'QuestionCD' (0x2809142c0) from NSManagedObjectModel (0x281d33ca0) claims 'QuestionCD'.
CoreData: warning: 'QuestionCD' (0x2809142c0) from NSManagedObjectModel (0x281d33ca0) claims 'QuestionCD'.
2021-08-20 20:17:03.576720+0300 CoreDataTest[27924:2275095] [error] warning: 'QuestionCD' (0x2809148f0) from NSManagedObjectModel (0x281d4cf50) claims 'QuestionCD'.
CoreData: warning: 'QuestionCD' (0x2809148f0) from NSManagedObjectModel (0x281d4cf50) claims 'QuestionCD'.
2021-08-20 20:17:03.576762+0300 CoreDataTest[27924:2275095] [error] warning: 'QuestionCD' (0x280914fd0) from NSManagedObjectModel (0x281d4e490) claims 'QuestionCD'.
CoreData: warning: 'QuestionCD' (0x280914fd0) from NSManagedObjectModel (0x281d4e490) claims 'QuestionCD'.
2021-08-20 20:17:03.576804+0300 CoreDataTest[27924:2275095] [error] error: +[QuestionCD entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[QuestionCD entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
2021-08-20 20:17:03.585701+0300 CoreDataTest[27924:2275095] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2021-08-20 20:17:03.585897+0300 CoreDataTest[27924:2275095] -[CoreDataTest.QuestionList encodeWithCoder:]: unrecognized selector sent to instance 0x281028400
2021-08-20 20:17:03.586179+0300 CoreDataTest[27924:2275095] *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2021-08-20 20:17:03.586297+0300 CoreDataTest[27924:2275095] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-20 20:17:03.586383+0300 CoreDataTest[27924:2275095] [error] error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-20 20:17:03.586553+0300 CoreDataTest[27924:2275095] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2021-08-20 20:17:03.586649+0300 CoreDataTest[27924:2275095] -[CoreDataTest.QuestionList encodeWithCoder:]: unrecognized selector sent to instance 0x281028400
2021-08-20 20:17:03.586799+0300 CoreDataTest[27924:2275095] *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2021-08-20 20:17:03.586874+0300 CoreDataTest[27924:2275095] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-20 20:17:03.586942+0300 CoreDataTest[27924:2275095] [error] error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-20 20:17:03.587088+0300 CoreDataTest[27924:2275095] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2021-08-20 20:17:03.587163+0300 CoreDataTest[27924:2275095] -[CoreDataTest.QuestionList encodeWithCoder:]: unrecognized selector sent to instance 0x281028400
2021-08-20 20:17:03.587301+0300 CoreDataTest[27924:2275095] *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2021-08-20 20:17:03.587372+0300 CoreDataTest[27924:2275095] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b0d5c0> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-20 20:17:03.587434+0300 CoreDataTest[27924:2275095] [error] error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-20 20:17:03.599299+0300 CoreDataTest[27924:2275095] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2021-08-20 20:17:03.599618+0300 CoreDataTest[27924:2275095] -[CoreDataTest.QuestionList encodeWithCoder:]: unrecognized selector sent to instance 0x281028400
2021-08-20 20:17:03.599908+0300 CoreDataTest[27924:2275095] *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2021-08-20 20:17:03.600018+0300 CoreDataTest[27924:2275095] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b04000> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280b04000> , <shared NSKeyedUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
Failed to save selected category: A Core Data error occurred.
源代码编辑器功能受限错误(这是什么?/为什么?):
核心数据实体:
核心数据保存功能:
func saveSelectedQuestion(questionTitle: String, id: String, questions: [QuestionList]) {
let questionsCD = QuestionCD(context: persistentContainer.viewContext)
questionsCD.title = questionTitle
questionsCD.id = id
questionsCD.questions = questions
do {
try persistentContainer.viewContext.save()
} catch {
print("Failed to save selected category: \(error.localizedDescription)")
}
}
型号:
class QuestionContainer: NSObject, Codable {
var questionCategories: [Question]
init(questionCategories: [Question]) {
self.questionCategories = questionCategories
}
}
class Question: NSObject, Codable {
var title: String
var id: String
var questions: [QuestionList]
init(title: String, id: String, questions: [QuestionList]) {
self.title = title
self.id = id
self.questions = questions
}
}
public class QuestionList: NSObject, Codable {
init(id: String, question: String, isQuestionImage: Bool, isSectionImage: Bool, imageURL: String, imageData: Data? = nil, sections: Sections, selected: String, correct: String) {
self.id = id
self.question = question
self.isQuestionImage = isQuestionImage
self.isSectionImage = isSectionImage
self.imageURL = imageURL
self.imageData = imageData
self.sections = sections
self.selected = selected
self.correct = correct
}
var id: String
var question: String
var isQuestionImage, isSectionImage: Bool
var imageURL: String
var imageData: Data?
var sections: Sections
var selected: String
var correct: String
}
public class Sections: NSObject, Codable {
init(a: String, b: String, c: String, d: String) {
self.a = a
self.b = b
self.c = c
self.d = d
}
var a, b, c, d: String
private enum CodingKeys: String, CodingKey {
case a = "A"
case b = "B"
case c = "C"
case d = "D"
}
}
我保存数据的页面:
我正在保存此页面的数据。
struct QuestionCategoryCellView: View {
@ObservedObject var questionCategoryCellViewModel = QuestionCategoryCellViewModel()
var questionTitle: String
var questionID: String
@Binding var questions: [QuestionList]
var body: some View {
Button(action: {
print("title: \(questionTitle)")
if questionCategoryCellViewModel.searchCategoryInCoreData(id: questionID) {
print("already saved")
} else {
questionCategoryCellViewModel.saveSelectedQuestionsToCoreData(questionTitle: questionTitle, id: questionID, questions: questions)
}
}) {
Text(questionTitle)
}
}
}
最佳答案
在您的错误消息中有四个这样的消息对:
2021-08-20 20:17:03.576623+0300 CoreDataTest[27924:2275095] [error] warning: 'QuestionCD' (0x28090c9a0) from NSManagedObjectModel (0x281d3d400) claims 'QuestionCD'.
CoreData: warning: 'QuestionCD' (0x28090c9a0) from NSManagedObjectModel (0x281d3d400) claims 'QuestionCD'.
但是仔细看,模型的内存地址每次都不一样。这里是0x281d3d400
,其他3次都不一样。那是因为内存中有四个不同的托管对象模型副本。您不止一次加载模型并混淆了核心数据。它是同一个实体,但 Core Data 对在哪里使用它感到困惑。
查看您的代码,发生这种情况是因为对于表格中的每个单元格,
您创建一个 QuestionCategoryCellView
QuestionCategoryCellView
创建一个 QuestionCategoryCellViewModel
QuestionCategoryCellViewModel
的每个实例都具有此属性:
let coreDM: CoreDataManager = CoreDataManager()
每个 CoreDataManager
调用 persistentContainer.loadPersistentStores
。
因此,每个单元格都会加载持久容器。那永远不应该发生。您有四个单元,每个单元都有自己的持久容器,每个容器都有自己的模型副本。
您的 CoreDataManager
或 persistentContainer
只需创建一次,然后用于每个单元格。我会说选择单例 CoreDataManager
但两者都可能有效。
一个简单的方法是
将此行添加到 CoreDataManager
:
static var shared = CoreDataManager()
更改 QuestionCategoryCellViewModel
,这样它就不会创建 CoreDataManager
,而是执行以下操作:
let coreDM: CoreDataManager = CoreDataManager.shared
如果你这样做,你就会避免这个问题。
然而,您会在代码中遇到一个完全不同的错误。您的数据模型使用 [QuestionList]
作为可转换属性的类型。但是 QuestionList
不符合 NSCoding
,因此当应用程序崩溃时它不起作用。在这里问一个不同的问题。
关于swift - [核心数据] :Multiple NSEntityDescriptions claim the NSManagedObject subclass 'Core Data Model' so +entity is unable to disambiguate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68866385/
主要思想是将 EF Core nuget 包添加到 .NET Core 库项目,然后在一堆应用程序(例如 ASP.NET Core、Win 服务、控制台应用程序)中使用该库,而无需在每个应用程序中配置
我想要实现的是编写一个简单的.net核心后台工作程序(.net core 3.1)的代码,在该工作程序作为Windows服务运行时,我在其中将数据写入SQL Server数据库(通过EF Core 3
关于 .Net Core SDK download page 二进制文件有什么用?它与安装程序有何不同? 最佳答案 二进制文件是 .NET Core 的编译代码。它们拥有运行 .NET Core 所需
.NET Core 和 Entity Framework Core 之间的区别?我们可以在 .NET Core 中使用 Entity Framework Core 吗?两者都有什么优势? 最佳答案 E
.NET Core 和 ASP.NET Core 到底有什么区别? 它们是相互排斥的吗?我听说 ASP.NET Core 是基于 .NET Core 构建的,但它也可以基于完整的 .NET 框架构建。
我对 ASP.NET Core 开发完全陌生。我正在尝试使用单个模型和 mysql 创建一个简单的 asp.net core Web api 来存储模型数据,然后我想使用 Swagger 将其作为 R
.NET Core 和 Entity Framework Core 之间的区别?我们可以在 .NET Core 中使用 Entity Framework Core 吗?两者都有什么优势? 最佳答案 E
好吧,作为一个新的 .net 开发生态系统,我有点迷失在核心工具、版本等方面。 有人可以解释我之间的区别吗 VS 2015 核心工具预览版 x - See here .NET Core/SDK 与否
我已阅读有关如何通过信号器核心集线器从后台服务向客户端发送通知的文档。如何从客户端接收到后台服务的通知? 后台服务应该只是一个单例。 public class Startup { public
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
非常简单的问题: 我正在尝试创建一个像这样的谓词构建器: var predicate = PredicateBuilder.False(); 但似乎在Net Core和EF Core中不可用。
在 .NET Core 自包含应用程序 中...我们需要在 project.json 中指定运行时 (RID) 我们希望我们的应用程序针对...发布为什么会这样? .NET Core 是跨平台的,与我
如何用 iCloud Core Data 替换我现有的 Core Data?这是我的持久商店协调员: lazy var persistentStoreCoordinator: NSPersistent
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 2 年前。 Improv
今天我正在学习新的 ASP.net 核心 API 3.1,我想将我的旧网站从 MVC4 转移到 Web API。除了一件事,一切都很好。数据库连接。在我的旧网站中,我为每个客户端(10/15 数据库)
我在 Visual Studio 2015 Update 3 和 .NET Core 1.0 中工作。我有一个 .NETCoreApp v1.0 类型的 Web API 项目。当我添加一个 .NET
我一直在尝试遵循 Ben Cull ( http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-proj
当我打开我的 vs 代码程序时,我收到以下消息: 无法找到 .NET Core SDK。 .NET Core 调试将不会启用。确保 .NET Core SDK 已安装并且在路径上。 如果我安装甚至卸载
我偶然发现了一个非常奇怪的问题。每当 Web 应用程序启动时,dotnet.exe 都会使用相当多的内存(大约 300M)。然而,当它触及某些部分时(我感觉这与 EF Core 使用有关),它会在短时
ASP.NET Core Web (.NET Core) 与 ASP.NET Core Web (.NET Framework) 有什么区别? .NET Framework 是否提供 similar
我是一名优秀的程序员,十分优秀!