提问人:YosiFZ 提问时间:9/6/2023 更新时间:9/6/2023 访问量:42
CoreData 崩溃 NSTaggedDate objectForKey
CoreData crash NSTaggedDate objectForKey
问:
我在我的 iOS 应用程序中使用 CoreData,我有一个函数可以为每个线程创建 NSManagedObjectContext:
var contextDict = [Thread:NSManagedObjectContext]()
var context:NSManagedObjectContext{
if let context = contextDict[Thread.current]{
return context
}else{
let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
context.persistentStoreCoordinator = persistentStoreCoordinator
contextDict[Thread.current] = context
return context
}
}
在初始化中,我使用以下命令创建主初始化:
contextDict[Thread.main] = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
突然间,我开始在这种方法上崩溃(并非一直如此):
if let context = contextDict[Thread.current]
崩溃日志:
-[__NSTaggedDate objectForKey:]: unrecognized selector sent to instance 0x8000000000000000
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'
*** First throw call stack:
(0x1b05b2d94 0x1a966c3d0 0x1b0727b14 0x1b05c91c8 0x1b062f9f0 0x1aa3c0b88 0x107919d00 0x10791c344 0x10790c220 0x10790ced0 0x107914bd0 0x107905814 0x1070ca3d8 0x107024e84 0x10799c520 0x10799e038 0x1079a60b0 0x1079a6df4 0x1079b3c74 0x20ff33ddc 0x20ff33b7c)
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'
terminating due to uncaught exception of type NSException
知道问题可以做什么吗?
答: 暂无答案
评论
contextDict
Date
perform()
performAndWait()
contextDict