1
votes

So, when my data model is ready, I tried to generate the subclasses when my data model file is open:

Editor -> Create NSManaged Object Subclasses

Okay, two files are generated, one is class declaration, the other is the property.

However, I was immediately prompted that I did a redeclaration of a class that already exists. This is where the original generated files are: previously generated files

My question is obvious:

  1. When were those two files generated?
  2. What to do if I want those files in my project navigator, and, of course, the same folder as my ViewController?
4
Set Codegento Manual/None in your .xcdatamodel for all entities seems to be the key. - David Wu

4 Answers

1
votes

It is common to make changes to an existing entity on the core data model.

Assume you add a field to an existing entity in the core data model, you would have to regenerate the class for that entity to include that field.

When regenerating that class there would be a an option to overwrite the existing files.

To answer your questions:

  1. It was probably created when the previous entity change was made.
  2. Move the previously generate files to the desktop. Then generate new files. See what the difference between the 2 sets of files are and take appropriate action. If I am not wrong, one file would be an extension and one is a class file.
0
votes

So, the correct answer seems like the one who commented on my question. Original post is here: https://stackoverflow.com/a/39933534/5642467.

Delete all generated NSManagedObject subclasses from your project, if exists.

Set Codegento Manual/None in your .xcdatamodel for all entities Clean project.---This is the key step, which is by default set to automatic by Xcode8.

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

0
votes

You are generating files which have already been generated for you by Xcode and thus get duplicate declarations.

Find detailes in this answer.

0
votes

In your xcdatamodeld you have to modify the Entity Class Codegen to Manual/None in the Utilities Panel before compile

enter image description here