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

4 Answers 4

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:

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

10 Comments

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.
"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.
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'.
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.
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.
|
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).

4 Comments

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?
I know quite a bit about how it works under the hood, you could say that anything I say about it should be authoritative. ;)
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).
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?
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.

3 Comments

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.
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.
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.)
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.

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.