3

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.

6
  • I am also getting the empty import statement. Seems like a new Apple bug. Commented Sep 18, 2016 at 19:52
  • It does seem like the issue should be handled in a better way than it is. Did you see my fix below? It seems like I was doing the wrong thing anyway Commented Sep 19, 2016 at 7:29
  • Yes, there is an issue I found: when creating new managed objects and casting them to one of my subclasses, it throws saying it cannot cast. The class name was in a namespace other that the current project's namespace. Commented Sep 19, 2016 at 15:18
  • I’m getting this same issue too now I’m building and testing the app. Do you know a workaround? Commented Sep 19, 2016 at 16:58
  • I left the Module field as the current project and I'm just deleting the empty import statement. I also do not use the code generation yet. Commented Sep 19, 2016 at 18:40

2 Answers 2

2

The Module field of the entity in the Data Model inspector had a value in it, I deleted this so now it’s empty and the placeholder reads “Global namespace”. This seems to have worked!

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

1 Comment

That, and I had to delete @nonobjc public class func fetchRequest() -> NSFetchRequest<Item> { return NSFetchRequest<Item>(entityName: "Item"); } that Xcode 8 created. Item is the Entity name in this case.
0

Core Data is heavily string-based. Using names such as "Entity" for your entities can lead to unexpected results. Also avoid using names in your data model such as "description", or "item" or "attribute" etc. If you do want to use those names, prefix them: names like "My_entity" or "ACEntity" are fine.

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.