0

DerivedData keeps returning into my project no matter how many different ways I try to delete it. This is causing a compile error.

I believe it is related to my deletion of my Core Data model class and extension (I realized I needed to add an additional property and this seemed easier than migrating since I hadn't actually implemented it yet). I deleted the files and removed the reference to these files, but that seems to have not worked. This is the error I've received:

enter image description here

I have tried:

-Cleaning
-Cleaning Build Folder
-Resetting Simulator Content and Settings
-Removing the DerivedData folder using "git rm -rf --cached ."
-Deleting DerivedData folder using Finder, Xcode and Terminal
-Deleting the Module Cache
-Deleting Xcode preferences (defaults delete com.apple.dt.Xcode)
-All of the above combined with quitting Xcode and/or restarting my computer
-Following all suggestions in the following threads on SO:

Xcode 6 Swift code completion not working

How can I delete derived data in Xcode 8?

Xcode keeps remaking derived data folder after I delete it

https://forums.developer.apple.com/thread/81265

https://iosdevcenters.blogspot.com/2015/12/how-to-delete-derived-data-and-clean.html

For the sheer hilariousness of it all, I have my project folder open in Finder when I try to run the project and can see the DerivedData folder being created as soon as I press the play button. Good times.

This is a view of my build/compile settings in Xcode to show that I don't have those files listed twice:

enter image description here

How can I fix this?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Pigpocket
  • 449
  • 5
  • 24

2 Answers2

1

You can't prevent Xcode from generating derived data for your project. No matter how many times you delete the folder, it will always regenerate.

I've come across similar issues in the past where the compile time error points to derived data, but something else is causing the issue.

From the looks of it, some of your files are being included twice in your project, and your getting name collisions. Check that you don't have duplicates in you build settings for bundled/compiled resources.

RPK
  • 1,830
  • 14
  • 30
  • I don't find any settings that appear appropriate for "bundled/compiled" under "build settings". In looking at "build phases", I see all the files necessary and living in their expected locations. I have updated my original question with an image of that. Do you have any other suggestions? – Pigpocket Feb 13 '18 at 15:25
  • where would these duplicates be in xcode? – Before The Empire Apr 04 '23 at 02:26
1

The error suggests that you have Core Data code generation turned on and also have a copy of the generated code (or at least a file with the same name) in your source code repository. That's why it complains of a duplicate. One is located in your Model folder, and the generated copy is located in derived data.

You can resolve this by either

  • Changing the setting in your data model so that Core Data doesn't generate code for this entity anymore, or
  • Deleting your copy and letting Core Data do its thing.

Either is valid and should work. Or, if the files are actually different in some meaningful way, rename yours so that the name doesn't conflict.

On a related note, the derived data folder always comes back because that's where Xcode puts all of the stuff it generates while compiling your project. It's not just generated source code, it's also things like compiled object code files and eventually the app itself. It comes back because that's how Xcode compiles the project.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • Can I change the name of the NSManagedObject subclasses that XCode creates without a problem? From why I’ve been taught, I shouldn’t touch the extension file in particular as it will screw up my model. Certainly just changing the name of these two files would be the easiest if that works. From a cleanliness perspective, what about the originally name files? Seems I can’t get rid of them no matter how hard I try... should I just forget about them? – Pigpocket Feb 13 '18 at 16:16
  • Class names for managed objects don't have to be the same as the entity name. You can configure that in the model editor. – Tom Harrington Feb 13 '18 at 16:49
  • I fixed this by changing the name of my Core Data class and extension as well as setting CodeGen to Manual/None. Thank you. – Pigpocket Feb 16 '18 at 00:35