ioscore-datansmanagedobjectbuild-time

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


I have a project with Core Data, storyBoard based, and 3 classes. The Core Data purpose is to save locations on a MapKit, but when I create the class "Spot", subclass of NSManagedObject, I get this Buildtime error. It says:

duplicate symbol _OBJC_METACLASS_$_Spot in:
    /Users/vitorferreira/Library/Developer/Xcode/DerivedData/CoreDataCity-buwqjxltijduybepebqqghhkrqwe/Build/Intermediates/CoreDataCity.build/Debug-iphonesimulator/CoreDataCity.build/Objects-normal/i386/Spot.o
    /Users/vitorferreira/Library/Developer/Xcode/DerivedData/CoreDataCity-buwqjxltijduybepebqqghhkrqwe/Build/Intermediates/CoreDataCity.build/Debug-iphonesimulator/CoreDataCity.build/Objects-normal/i386/Spot+CoreDataClass.o
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

In a previous comment (this is an edited question) - it's been said the reason is duplicated code in the Libraries...But honestly I don't get it...Any help would be much apreciated


Solution

  • 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.

    enter image description here

    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.

    enter image description here

    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.