Core Data code generation causes build failure

I’m using the new Xcode 8 feature of code generation for my Core Data model using `Class Definition` as the `Codegen` option.


When I build I get the following output for each of my entities:


<unknown>:0: error: no such file or directory: ‘/path/to/DerivedSources/CoreDataGenerated/Model/.Entity+CoreDataClass.swift'

<unknown>:0: error: no such file or directory: ‘/path/to/DerivedSources/CoreDataGenerated/Model/.Entity+CoreDataProperties.swift’

...

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1


On inspecting the files I can see the following:


Entity+CoreDataClass.swift:


import Foundation

import CoreData


public class Entity: NSManagedObject {

}


Entity+CoreDataProperties.swift


import Foundation

import CoreData

import

extension Entity {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Entity> {

return NSFetchRequest<Entity>(entityName: “Entity");

}

@NSManaged public var title: String?

}


In the second, the obvious thing that shouldn’t be there is the empty import statement, which I’m guessing is causing the crash.


Could I be doing something wrong? Is this a bug?


I’ve tried all the usual, clean, clean build folder, restart Xcode/Mac with no luck.

I have spent the last few days tryng to find a work around, but it appears to be a bug that stops you using Core Data in an app. One or two other people seemeed to have tripped over it, but I can't believe more people haven't seen it as it stops you using core data in your app.


http://www.openradar.me/27151410


It is in Xcode 8 and Xcode 8.1 beta. Unfortunately it looks like a case of waiting for a fix from Apple.

I'm having the same issues, but with codegen set to Category/Extensions. I have to set the entities to Manual/None, then manually create the subclasses and extentions from the Editor menu, to even get the project to build.


I too have the empty import statement at the beginning of the class file and have deleted it to get rid of the error.


The main problem is that, if I have xcode codegen set to Category/Extensions (even after manually generating the files), I get an error on the build that says "no file or directory ", for the three entites I have in my model.


I am new to core data and have no idea if the manually generated classes will work properly with the new features of the core data stack.

If you go to your data model and look at Configurations -> Default you will probably see that in the Class column everything is prefixed with a ".". To fix this, go to each of your entities and on the right delete everything inside the "module" setting so that it goes to "Global namespace". This should remove the "." and will hopefully mean that your files are now found. If you clean and build again it should all work.

Core Data code generation causes build failure
 
 
Q