Duplicate Symbol Error in NSManagedObject Subclass

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 Codegento 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 Codegento 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

Leave a Comment