7

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.

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
Darko
  • 615
  • 7
  • 21
  • 1
    Check: http://stackoverflow.com/a/40357746/1457385, and maybe http://stackoverflow.com/a/39933534/1457385 – shallowThought Nov 06 '16 at 10:39
  • I've checked both of them, tried them and still got the error. I have now made an app without generating subclasses and it works. So I'm guessing they are implementing coredata subclasses automatically now ? – Darko Nov 06 '16 at 12:38
  • Depending on your settings. It's explained in detail in the mentioned answers. You might also want to see WWDC video "Whats new in Core Data": https://developer.apple.com/videos/play/wwdc2016/242/ – shallowThought Nov 06 '16 at 12:41
  • I have seen that video :) the strange thing is that I have one app that uses subclasses but now the app I created a few days ago works without subclasses. The xCode release notes mention nothing of this sort. – Darko Nov 06 '16 at 12:43
  • Post a screenshot of your Entities "Code Gen" setting. – shallowThought Nov 06 '16 at 12:49

3 Answers3

9

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.

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
  • Thanks for the answer. During lunch deleted the manually created NSManagedObject subclass and all working correctly now – Charlie S Nov 28 '18 at 13:45
1

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

Aaron
  • 6,466
  • 7
  • 37
  • 75
  • Hey, thank you for the reply, that doesn't solve the issue, it still produces the same error. – Darko Nov 06 '16 at 08:39
  • If you go to your project's build phases, under compiled sources, is the file listed there twice? – Aaron Nov 06 '16 at 08:49
  • Nope, just once. But the weird thing is that I can instantiate my Card object even when I don't create the subclasses. – Darko Nov 06 '16 at 09:06
1

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.

Rajat
  • 10,977
  • 3
  • 38
  • 55