2

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

FuManchu
  • 145
  • 2
  • 11

3 Answers3

12

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.

Warren Burton
  • 17,451
  • 3
  • 53
  • 73
1

This means you have duplicate code somewhere in your libraries, have you imported core data in more than one location?

MacStation
  • 411
  • 4
  • 20
  • 1
    I dont think so; actually I have the same problem in a complete project. I've clean the builds, searched the librarys paths - as suggested in one post - and all i got is "Debug" and "Release" – FuManchu Feb 03 '17 at 16:12
  • Your post says you just created this project, does it happen again if you start a completely new project with core data? – MacStation Feb 03 '17 at 16:31
  • yes, i'm trying to duplicate the other one with the same issue, but in the new one I get the error right from the start – FuManchu Feb 03 '17 at 16:44
  • I have no clue, I tried replication your error and couldn't. Sorry, but good luck! – MacStation Feb 03 '17 at 16:53
  • Well, I guees I'm gonna need it...:) – FuManchu Feb 03 '17 at 17:12
0

Based on the name of the duplicated symbol, I'm guessing this is an Objective C project and you have the following (or similar) in both Spot.h and Spot+CoreDataClass.h:

@interface Spot: NSManagedObject

_OBJC_METACLASS_$_Spot is the name the compiler gives to the Spot metaclass, which is the type of the object returned by +[Spot class].

Dave Weston
  • 6,527
  • 1
  • 29
  • 44