NSManagedObject subclasses duplicate declaration

家住魔仙堡 提交于 2019-12-20 04:09:22

问题


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?

回答1:


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

Find detailes in this answer.




回答2:


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.



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/40331847/nsmanagedobject-subclasses-duplicate-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!