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.

5
  • 1
    Check: stackoverflow.com/a/40357746/1457385, and maybe stackoverflow.com/a/39933534/1457385 Commented Nov 6, 2016 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 ? Commented Nov 6, 2016 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": developer.apple.com/videos/play/wwdc2016/242 Commented Nov 6, 2016 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. Commented Nov 6, 2016 at 12:43
  • Post a screenshot of your Entities "Code Gen" setting. Commented Nov 6, 2016 at 12:49

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. During lunch deleted the manually created NSManagedObject subclass and all working correctly now
1

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

3 Comments

Hey, thank you for the reply, that doesn't solve the issue, it still produces the same error.
If you go to your project's build phases, under compiled sources, is the file listed there twice?
Nope, just once. But the weird thing is that I can instantiate my Card object even when I don't create the subclasses.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.