Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode is looking for core data entity names with dot; not compiling

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

like image 698
MarkAurelius Avatar asked Oct 08 '16 10:10

MarkAurelius


3 Answers

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)

  • Clean project
  • Clean DerivedData folder

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:

  • Clean project
  • Clean DerivedData folder
  • Restart Xcode
like image 96
shallowThought Avatar answered Nov 14 '22 10:11

shallowThought


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

like image 4
Chris Hanson Avatar answered Nov 14 '22 11:11

Chris Hanson


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.

like image 1
matt Avatar answered Nov 14 '22 12:11

matt