Search code examples
swiftxcodecore-datacode-generation

Codegen for CoreData entity not working in Xcode 11


So I am pretty new to CoreData in Xcode and I have been looking for tutorials to see how to get more familiar with it and start working with it. A tutorial I have been watching, mentions that we need to Generate code for an entity that I created. I select Editor -> Create NSManagedObject Subclass to generate the code for the entity. But the files generated come full of errors and warnings that I haven't caused. I will attach screenshots for some more details.

Entity created in CoreData

That's the entity that I am creating in CoreData

First generated file

That's the first generated file for the entity

Second generated file

That's the second file generated for the entity

The below are the errors and warnings I am getting:

File 'Person+CoreDataClass.swift' is part of module 'CoreData'; ignoring import

File 'Person+CoreDataProperties.swift' is part of module 'CoreData'; ignoring import

Only classes that inherit from NSObject can be declared @objc

Cannot find type 'NSManagedObject' in scope

Cannot find type 'NSFetchRequest' in scope

Note that I have enabled CoreData when I first created the project and I haven't made any changes to any other files in the project.

I would appreciate any kind of help since I haven't got any experience yet with CoreData. Thank you!


Solution

  • Try creating a new project with a different name (not CoreData)