Character duplication error in NSManagedObject subclass

I just created a demo project with Core Data.

I created a Userinfo object in my data model. Now I have subclassed the NSManagedObject this object.

Xcode autogenerated these 4 classes.

enter image description here

Now, when I create a project, it throws this error:

enter image description here

I did everything I know to remove the duplication error, but nothing helped.

I think this is an Xcode error. Please help.

+5
source share
1 answer

You generate files that Xcode has already created for you, and thus receive duplicate ads. Detailed information about this feature (new in Xcode 8) can be found in this WWDC video .

Two possible fixes:

1) Use subclasses of ManagedObject created under Xcode (recommended, modern approach)

  • Remove all created NSManagedObject subclasses from your project, if they exist.
  • Set Codegen to Class Definition in .xcdatamodel for all objects
  • Make sure Module blank (Global Namespace is light gray) (Apple workaround, see this answer )

Note:

Never add automatically generated files to your project. Even you do not see the generated files in your project, Xcode has a link to it, so you can write extensions, etc. For instance:

 extension MyEntity { func doSomething() { // } } 

Alternatively, you can invoke + click on the generated file in Xcode.

2) Manually generating a trigger subclass (a rather paranoid, but bulletproof approach, ignoring the new Xcode features)

  • Remove all created NSManagedObject subclasses from your project, if they exist.
  • Set Codegen to Manual/None in .xcdatamodel for all objects
  • Clear project
  • Empty DerivedData folder
  • Restart xcode
  • Manually subclass NSManagedObject (in the Editor menu)
  • Make sure these files are added to your project.
  • to build
+9
source

Source: https://habr.com/ru/post/1260522/


All Articles