[英]Core Data Entities multiple build configurations
I have 3 build configurations, Debug, Release and Development. 我有3个构建配置,即Debug,Release和Development。 For Development I have created a new Scheme with a new bundleID, Product name etc so I can see which one is DEV and DEBUG on my phone. 对于开发,我创建了一个新方案,其中包含新的bundleID,产品名称等,因此我可以在手机上看到哪个是DEV和DEBUG。
I am using Core Data and for the DEBUG with the original bundleID everything works fine, but when I switch to use the Development one, I get an error when I try to create a new entity with name: 我正在使用Core Data,并且对于具有原始bundleID的DEBUG来说,一切正常,但是当我切换为使用Development One时,尝试创建具有名称的新实体时出现错误:
NSEntityDescription.insertNewObject(forEntityName: "MyEntity", into: managedContext)
The error I get: 我得到的错误:
Could not cast value of type 'NSManagedObject_MyEntity_' (0x600002d62b20) to 'AppName_DEV.MyEntity' (0x102bf9368).
It seems like it is trying to get the MyEntity class from my "AppName DEV" scheme not the "AppName". 似乎正在尝试从我的“ AppName DEV”方案而不是“ AppName”中获取MyEntity类。 I can't find any Build Settings where I could point it to use the same model? 我找不到任何可以指向使用相同模型的构建设置?
Any ideas on how to use core data with multiple build configurations? 关于如何在多个构建配置中使用核心数据的任何想法?
Ok, I found the problem. 好的,我发现了问题。 Since I was trying to revive a very old app originally written in swift 2, it occurred to me that I might double check how was the data model created. 由于我试图恢复一个最初用swift 2编写的非常老的应用程序,因此我想到我可能要仔细检查数据模型的创建方式。 After hours of tinkering with the core data set up process, I changed 2 things that finally get it to work. 经过数小时的核心数据设置过程的修改,我改变了两件事,终于使它起作用。
1.) In the .xcdatamodeld
file, on the right side in the Data Model Inspector
, make sure that you have the Module
field EMPTY I had my AppName Inside, which was the same as the original target name. 1.)在.xcdatamodeld
文件中,在“ Data Model Inspector
的右侧,确保您具有“ Module
字段EMPTY,我的AppName位于内部,该名称与原始目标名称相同。
2.) I added @objc(EntityName) to the NSManagedObject subclass I had. 2.)我将@objc(EntityName)添加到了我拥有的NSManagedObject子类中。
If you have an issue like that, hope that whis will help you, good luck! 如果您有这样的问题,希望whis能为您提供帮助,祝您好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.