Duplicate Symbol Error in Nsmanagedobject Subclass

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)

Sample Image

  • Clean project
  • Clean DerivedData folder (Optional. To be on the save side)
  • build

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

Error: duplicate symbols for architecture armv7 after change Core Data Model

Check if there are multiple NSManagedObject subclass files generated after making this change. There should be duplicate files generated after your attribute change. Check in finder window as well as in project and then remove the duplicate files. That should fix this issue.

Apple Mach-O Linker Error in project with Coredata, when creating NSManagedObject Class

Xcode 8.2 (or maybe earlier) by default creates NSManagedObject subclass files completely invisibly and automatically if you have the entity Codegen mode set to Class Definition or Category/Extension.

Sample Image

So if you have the entity set to this mode…

DO NOT manually generate with Editor > Create NSManagedObject Subclass… or you'll have two copies and duplicated symbols.

The auto-generated files live down inside the derived data folder. You can Command click the objects to get to their definitions.

Sample Image

and you may find when adding Entities or making big changes that it takes a Clean->Build cycle to pick it up.

If you don't want this behaviour switch Codegen to Manual/None

NOTE

Feb 2017 - The templates are not 100% correct and the generated class func fetchRequest() is not usable due to being ambiguous.

Linker Duplicate Symbol error due to circular reference

Found the solution to my problem in this answer. I just had to remove the .m files from the Compile Sources.

xcode link error after Create NSManagedObject Subclass doesn't overwrite previous version

Check you haven't generated the same class to two different locations, for instance one in the root project folder and one in a subfolder.



Related Topics



Leave a reply



Submit