Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when creating NSManaged Subclass in Xcode 8.2 beta

I am getting this error that seems to warn me of duplicate files. Am I missing something or Xcode now doesn't require creating nsmanaged subclass to operate on core data. I tried creating a blank project and the same thing happens. Here is the error data

<unknown>:0: error: filename "Card+CoreDataClass.swift" used twice: '/Users/user/Documents/Developer/coredata/Card+CoreDataClass.swift' and '/Users/user/Library/Developer/Xcode/DerivedData/coredata-gicbdltjgiidbcfxaqqaxvkqwnnk/Build/Intermediates/coredata.build/Debug-iphonesimulator/coredata.build/DerivedSources/CoreDataGenerated/coredata/Card+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Card+CoreDataProperties.swift" used twice: '/Users/user/Documents/Developer/coredata/Card+CoreDataProperties.swift' and '/Users/user/Library/Developer/Xcode/DerivedData/coredata-gicbdltjgiidbcfxaqqaxvkqwnnk/Build/Intermediates/coredata.build/Debug-iphonesimulator/coredata.build/DerivedSources/CoreDataGenerated/coredata/Card+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

This implies to me that the files have already been automatically created. I can even make a Card object without manually creating the subclasses. Thanks.

like image 446
Darko Avatar asked Nov 06 '16 08:11

Darko


3 Answers

The issue here is that as of Xcode 8, new projects using Core Data and new Core Data data models are configured to use automatic code generation by default. That means you don’t have to explicitly generate code for your Core Data entities any more, Xcode will take care of that for you. If you leave automatic code generation on and also manaully generate Swift classes for your entities, you’ll see an error like this.

You can disable automatic code generation for an entity in the entity inspector, or you can remove the manually-generated code from your project. Either of the two should fix this.

like image 177
Chris Hanson Avatar answered Nov 03 '22 01:11

Chris Hanson


Try clearing your derived data via Xcode > Preferences > Locations > little grey arrow > move contents to the trash. Then clean the project and rebuild.

like image 26
Aaron Avatar answered Nov 03 '22 01:11

Aaron


First check in you project that you have not imported this file Card+CoreDataProperties twice, also check that you have not created this class Card+CoreDataProperties twice throughout your project, also delete derived data and clean your project.

like image 1
Rajat Avatar answered Nov 03 '22 02:11

Rajat