未为测试目标生成核心数据类 [英] Core Data classes not generated for test target
问题描述
我使用Core Data的自动生成的类。除了测试目标外,我的项目还有3个目标。对于每个目标,将正确生成Core Data类,我通过检查Derived Data文件夹进行了验证。但是,尽管在核心数据模型文件中打勾了测试目标,但它并未生成类。当我尝试引用测试目标中的一个核心数据类时,这会导致未声明的标识符和未声明类型的使用错误。我该如何解决?
I use Core Data's automatically generated classes. My project has 3 targets in addition to the test target. For each target, the Core Data classes are properly generated which I verified by inspecting the Derived Data folder. However, classes are not generated for the Test Target despite it being ticked in the Core Data model file. This causes an "undeclared identifier" and "Use of undeclared type" errors when I try to reference one of the Core Data classes in the test target. How can I fix this please?
推荐答案
这是由于Xcode(8.3.1)中存在一个错误,该错误会自动生成尽管项目编译成功,但在全局路径上找不到NSManagedObject类(代码生成设置为类定义)。唯一的解决方法是通过将每个实体的代码生成设置为 Manual / None来手动生成NSManagedObject类。
This was due to a bug currently in Xcode (8.3.1) where auto-generated NSManagedObject classes (codegen set to "Class Definition") cannot be found on the global path despite the project compiling successfully. The only way around it is to which to manual generation of the NSManagedObject classes by setting codegen for each entity to "Manual/None".
这篇关于未为测试目标生成核心数据类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!