You are generating files which have already been generated for you by Xcode and thus get duplicate declarations. Details about this feature (new in Xcode 8) can be found in this WWDC video.
Two possible fixes:
1) Use the Xcode generated ManagedObject
subclasses (the recommended, modern approach)
- Delete all generated NSManagedObject subclasses from your project, if exists.
- Set
Codegen
to Class Definition
in your .xcdatamodel
for all entities
- Make sure
Module
is empty ("Global Namespace" in light gray) (workaround an Apple bug, see this answer)
Note:
Never add the automatically generated files to your project. Even you do not see the generated files in your project, Xcode has a reference to it, so you are able to write extensions and such. For instance:
extension MyEntity {
func doSomething() {
//
}
}
Also, you can command+click to the generated file within Xcode.
2) Trigger subclass generation manually (a rather paranoid but bullet-prove approach, ignoring the new Xcode features)
- Delete all generated NSManagedObject subclasses from your project, if exists.
- Set
Codegen
to Manual/None
in your .xcdatamodel
for all entities
- Clean project
- Clean DerivedData folder
- Restart Xcode
- Manually generate
NSManagedObject
subclasses (in "Editor" menu)
- Make sure those files are added to your project
- build
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…