6

I have been working on a project for a while, and recently upgraded to Xcode 8 and Swift 3.0 and iOS 10. But since I did that I have not been able to compile.

I am getting an error for each of my entities: :0: error: no such file or directory: ''/Users/mark/Library/Developer/Xcode/DerivedData/.../.Account+CoreDataProperties.swift' Each case has a . (dot) prefix before the entity name: .Account+CoreDataProperties.swift.

I changed the Code Gen from "Category / Extension" to Manual / None, I do a clean and clean directory, an delete the DerivedData directory. Interestingly, when I look in the appropriate directory there is an actual file there, just without the dot prefix.

This is very confusing. Can anyone explain it? I need to solve this to be able to continue with core data.

TIA Mark

MarkAurelius
  • 1,203
  • 1
  • 14
  • 27

4 Answers4

9

The dot files are generated by Xcode8. See WWDC2016. I ran into the same issue after having to delete derived data due to another issue.

Two possible fixes:

1) The recommended, modern approach

  • Delete all generated NSManagedObject subclasses from your project, if exists.
  • Set Codegento Class Definition in your .xcdatamodel for all entities
  • Make sure Module is empty ("Global Namespace" in light gray) (workaround an Apple bug, see @Chris Hansons answer)

Note: Even you do not see the generated files in your project, Xcode has a reference to it, so you are able to write extensions and such. For instance:

extension MyEntity {
    func doSomething() {
        //
    }
}

Also, you can command+click to the generated file within Xcode.

2) A rather paranoid but bullet-prove approach, ignoring the new Xcode features

  • Delete all generated NSManagedObject subclasses from your project, if exists.
  • Set Codegento Manual/None in your .xcdatamodel for all entities
  • Clean project
  • Clean DerivedData folder
  • Restart Xcode
  • Manually generate NSManagedObject subclasses (in "Editor" menu)
  • Make sure those files are added to your project
  • build

If your problem persists, repeat:

shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • Thanks for the advice. I had been trying something similar to that approach. What exactly do you mean by "Clean DerivedData folder"? There is alt + Product | Clean, where the alt changes the menu item caption from "Clean" to "Clean build folder". After carrying out your procedure my current situation is that I have extensions with 2 issues: the extra "import" with no argument, and no class declaration. – MarkAurelius Oct 09 '16 at 01:57
  • "Clean DerivedData folder": Added how to link in answer. "the extra import: this is an Apple bug. Delete the extra "import". "no class declaration": I did not understand. Please describe more detailed. Maybe create a new question for that as it sounds like an independent issue to me. Post a link in the comment here, I will try to help then. – shallowThought Oct 09 '16 at 12:32
  • OK, thanks, I have tried that. But I had done it before I posted. Unfortunately it doesn't solve my problem. This time, I had to go the Preferences route; XCode 8 doesn't have a Projects item in the Window menu. I still get the extra import statement with no argument. When I remove that line it still doesn't work because it is in delaying an extension, "extension Venue" (Venue being an entity in my data model) but there is no "class Venue" declared anywhere. The 1st error is on extension Venue saying "Use of undeclared type 'Venue'. – MarkAurelius Oct 10 '16 at 09:31
  • If you cleaned all, set CodeGen to None and triggered "Create NSManaged Object Subclass..." manually, two files are generated per Entity. `EntityName+CoreDataClass` and `EntityName+CoreDataProperties`. – shallowThought Oct 10 '16 at 10:43
  • I appreciate your stamina. Any idea why the +CareDataClass.swift files are not appearing? Because each time I do this, with "Codegen = Manual/None", I get a +CoreDataProperties.swift file with extensions but no class declarations, but no files with the classes. – MarkAurelius Oct 11 '16 at 02:26
  • I suspect this means your project still holds a reference to `EntityName+CoreDataClass` (has not been fully cleaned). I just gave it a try: Create new Project, add new file -> CoreData model, add Entity, add attribute, assure Entity CodeGen is set to Manual/None, "Create NSManaged Object Subclass...". Two files generated. Try this on your side to assure it's working on a virgin project. I'm useing Xcode8.0 (8A218a) – shallowThought Oct 11 '16 at 10:50
  • Yes, I did, and I got both files. I created a new project and added and entity and and generated the files. Then deleted and regenerated them. No problems with extra import without argument. It was all sweet. Version 8.0 (8A218a) as well. I am thinking of creating a new project and recreating my database from scratch. – MarkAurelius Oct 11 '16 at 11:32
  • Good to hear. I don't think that creating a new project necessary. Clean Project, delete derived Data, maybe search your project for "EntityName+CoreDataClass" to assure there is no reference left, restart Xcode. Good luck. Let us know, if you need further help. – shallowThought Oct 11 '16 at 12:38
  • None of the above is necessary, it should be sufficient to just remove customization of the entity's module and ensure that the entity is set to generate a class. – Chris Hanson Oct 11 '16 at 19:09
  • I have searched through the whole project. There are no files declaring classes for the entities. I did have a leftover file called OfferingCounter-Bridging-Header.h (OfferingCounter being the name of the app and the database), consisting of lines like this #import "Venue.h" where Venue is an entity. I am guessing that the fix will be in the project settings plist, e.g. that bridging header shows up in a search for ".h", in a setting, – MarkAurelius Oct 12 '16 at 02:15
4

This occurs when the module of an entity is set to "Current Product Module" (e.g. to be within the Swift namespace, rather than the global Objective-C namespace).

The workaround for this is to remove the customization of the "Module" field of the entity, so it has the default value of "Global namespace" (in light gray text).

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
  • Nice one. Do you know what happens under the hood by changing this value? I assume the files are generated to "somewhere else" than DerivedData. Do you know where? – shallowThought Oct 12 '16 at 11:04
  • 1
    I know quite a bit about how it works under the hood, you could say that anything I say about it should be authoritative. ;) – Chris Hanson Oct 16 '16 at 23:33
  • The files are generated into the DerivedData directory for the specific target to which the model belongs, in the Intermediates directory under `«TargetName».build/DerivedSources/CoreDataGenerated`, with a separate directory per model (in case the target has multiple models). – Chris Hanson Oct 16 '16 at 23:33
  • 1
    Can you maybe edit your answer to explain more on the background what "Current Product Module" is supposed to do and why using it causes problems? – shallowThought Oct 17 '16 at 11:37
1

I changed the Code Gen from "Category / Extension"

Change Codegen to Class Definition.

enter image description here

Now get rid of whatever you were doing in code to turn your entities into pseudo-classes. Your entities are now real classes!

You will now be able to pare your code down considerably. You no longer have to cast down to specify an entity type as a class. When you fetch Person objects, your fetch results is a generic parameterized on Person, and so each fetched object is a Person. Similarly, to make a new Person, just call Person(context:) and configure, and save the store. The word "entity" will probably cease to exist anywhere in your code.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • You should watch the WWDC video on this topic. It's pretty eye-opening. Your code is about to get a lot shorter and cleaner. – matt Oct 11 '16 at 20:13
  • I have seen that video. And I tried Global namespace and Codegen = Class Definitio but I got the extension, not the class definitions. Something is screwy with my project, I think, presumably in the conversion from earlier versions. – MarkAurelius Oct 12 '16 at 02:27
  • Make sure the Minimum Tools Version for your model (in the file inspector) is set to either Automatic or Xcode 8.0, and that you explicitly save the document after making changes to it, such as changing Codegen for an entity from Class Definition to Category/Extension. (That should be addressed in Xcode 8.1 beta 3.) – Chris Hanson Oct 16 '16 at 23:35
1

I have solved it. I was about to recontruct the whole app from scratch to avoid whatever the issue was, and I noticed that the entity class files were in the directory, even though they weren't visible in Xcode. So I deleted those files and that cleared that hurdle.

I'm very happy now.

MarkAurelius
  • 1,203
  • 1
  • 14
  • 27