相关疑难解决方法(0)

CoreData:警告:无法加载命名的类

我正在使用Xcode 6.1将现有的Objective-C电视节目应用程序复制到新的Swift版本,并且我在使用CoreData时遇到了一些问题.

我创建了一个包含4个实体的模型,创建了它们的NSManagedObject子类(在Swift中),并且所有文件都设置了适当的应用程序目标(用于"编译源代码").

每当我尝试插入一个新实体时,我仍然会收到此错误:

CoreData:警告:无法为实体"显示"加载名为"显示"的类.找不到类,而是使用默认的NSManagedObject.

一些评论:

保存到Core Data时,我使用父子上下文方式来允许背景线程.我这样做是通过使用以下方法设置ManagedObjectContext:

lazy var managedObjectContext: NSManagedObjectContext? = {
  // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
  let coordinator = self.persistentStoreCoordinator
  if coordinator == nil {
    return nil
  }
  var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType)
  managedObjectContext.persistentStoreCoordinator = coordinator
  return managedObjectContext
}()
Run Code Online (Sandbox Code Playgroud)

并使用以下方法保存数据:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, …
Run Code Online (Sandbox Code Playgroud)

multithreading core-data nsmanagedobject swift

91
推荐指数
6
解决办法
3万
查看次数