Read this answer if error message references Core Data files
www.un.org/Depts/DGACM/index_spanish.htm 综合症: 您可能拥有自动生成和人工生成的核心数据管理对象类别档案。
如果该错误的第一行指的是Foo+CoreDataProperties.o或Foo+CoreDataClass.o文档,则适用这一答案。 例:
<代码>error>: 多个指挥单位生产/Users/me/Library/Developer/Xcode/DerivedData/MyApp-uebslaqdwgldkjemijpdqmizgyzc/Build/Intermediates.noindex/ MyApp /Debug-iphonesimulator/ MyApp.build/Objects-normal/x86_64/Foo+CoreDataProperties.o:
<代码>1)MyApp(项目MyApp)汇编了快速源文档的指令编码>。
<代码>2)MyApp(项目MyApp)汇编了快速源文档的指令编码>。
可以通过扩大“建筑说明”的Compile Source files部分来看待这一根本原因。 例如:
<unknown>:0: error: filename "Address+CoreDataClass.swift" used twice: /Users/myUserName/Projects/Jnky/Foo+CoreDataProperties and /Users/jk/myUserName/Developer/Xcode/DerivedData/MyApp-uebslaqdwgldkjemijpdqmizgyzc/Build/Intermediates.noindex/MyApp.build/Debug/MyApp.build/DerivedSources/CoreDataGenerated/Jnky/Foo+CoreDataProperties.swift
The first file mentioned there is a source file in your project directory, which someone generated by selecting your data model in the Project Navigator and clicking in the menu Editor > Create Managed Object Subclass. This feature was added in Xcode 7 or so.
The second file is a file of the same name but which is buried in Xcode s DerivedData
. This file is generated automatically by Xcode during every build if the data model (.xcdatamodeld
) file is included in the target s Compile Sources build phase. This feature was added in Xcode 9 or so. Zero, one or two files are generated for each entity/class, depending on the setting of the Codegen popup. That popup is in the Data Model Inspector when you select an entity while editing your data model…
这些环境是:
- Manual/None No files are generated
- Category/Extension One file, Foo+CoreDataProperties.m or .swift is generated, containing an Objective-C category or Swift extension.
- Class Definition That same Category/Extension file is generated, and in addition a Foo+CoreDataClass.m or .swift is generated, containing class declaration and definition.
因此,如果一位老的X条码习惯的开发商(如我)开始采用新的X条码项目,就会出现问题。 我们认为,我们需要使用Create Managered Object Subqu menu项目,我们这样做是为了建立我们在“Nagator”项目中能够看到的档案,而没有认识到我们在“Codegen上所处的环境正在造成X条码制造重复的档案,而“ Apple”项目在“Nagator”项目中并不显示,因为它们没有信托开发商读和<>heed<<<>>>>>>> / 该档案自动生成,不应编辑。
Solution 1 - Use the Older Way
如果数据模型仅采用一种情况,则你可以将其所有自动数据Codegen:
- Open the problem Target s Build Phases (In Project Navigator, select project, then in list of TARGETS which appears, select the problem target, then tab Build Phases).
- Expand the Compile Sources entry and find the problem data model (
.xcdatamodeld
file).
- Delete it from the compile list
- Ensure the data model is included in the Copy Bundle Resources list.
Solution 2 - Core Data Magic For Beginners
在这方面,你走得更新的道路。
- Leave your data model as is in that Compile Sources.
- In each Entity Inspector in your data model, set Codegen to Class Definition.
- In the Project Navigator, delete and trash any Foo+CoreDataClass files, and rename any Foo+CoreDataProperties.m or .swift files to something like Foo+MyProperties.
- In each Foo+MyProperties.m or .swift file, if there are properties generated by Xcode, delete these properties because they will be in the hidden files created by Codegen.
With this solution, your class definitions are generated automatically from the data model on each build. You can t even see them. It is Core Data Magic, nice and simple for beginners.
Solution 3 - For Most Real-World Apps
但是,如果你真想增加非管理的财产,解决办法2就没有好处。 (目标-C不允许在类别中添加财产,快速不允许在延伸中添加所储存的财产。) 因此,在大多数现实世界观中,你很可能要把解决办法1和2放在一半。
- Leave your data model in the list of Compile Sources
- In each Entity Inspector in your data model, set Codegen to Category/Extension.
- In the Project Navigator, delete and trash any Foo+CoreDataClass.m or .swift files, and, to reduce future confusion, rename any Foo+CoreDataProperties.m or .swift files to maybe just Foo.m or .swift.
- Ensure that each Foo.m or .swift file contains the class definition, to which you can add your own non-managed properties.
(Acknowledgments to the answer by Positron. My answer here explains why Positron s answer (my Solution 1) works, and adds Solution 2 and Solution 3.)