1

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?
shallowThought
  • 19,212
  • 9
  • 65
  • 112
David Wu
  • 105
  • 2
  • 13

4 Answers4

1

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.
user1046037
  • 16,755
  • 12
  • 92
  • 138
0

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

Community
  • 1
  • 1
David Wu
  • 105
  • 2
  • 13
0

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

Find detailes in this answer.

Community
  • 1
  • 1
shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • One of the problems of using Class Definition is that when plug in the phone and change the build device to it, the auto-generated sub class files automatically lose there reference -- that is -- xcode will prompt the error of not having definition of core data classes used in your ViewController. – David Wu Nov 05 '16 at 02:50
  • Builds fine here with the mentioned settings. If your problem persists, maybe post a link to a minimal sample project showing the issue, so we can take a look. – shallowThought Nov 05 '16 at 15:23
0

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

enter image description here

Bisca
  • 6,380
  • 2
  • 19
  • 32