Create NSManagedObject class in Xcode 8.1 showing error

I created the NSManagedObject class for an entity in Xcode 8 using the edition-> create NSManagedObject subcategory. It creates 2 files with the extension +CoreDataProperties , and another with the extension +CoreDataClass .

After adding these files, I get an error Failed to execute the Linker command and display duplicate files ... I checked if the file is added twice to the search engine, as well as to Xcode

If I delete the CoreDataClass.m file from compilation sources, the error disappears, but the application crashes. I cannot access the properties of an entity class. How to solve this problem?

+5
source share
3 answers

When creating an NSManagedObject, make sure that Codegen is Manual/None .

Select Entity in the Data Model window (right) in the Class section, change Codegen to Manual/None , then create your NSManagedObject .

If you have already created you NSManagedObject and a duplicate file error has already been shown, delete the Derived Data (File β†’ Workspace Settings β†’ Click the link for derived data), Clean Build Folder (Redundant? Not sure), and create an NSManagedObject as shown above.

+2
source

Yes. Since post Xcode 8.0 now creates a class file for your main data object with your own. You can add an extension (for this class) if you want to write additional functionality.

SO just removes the clean class projects (maybe restarting Xcode if the problem persists) and you will be well off.

0
source

Swift 3.2

by convention and a more general approach, you should generate categories / extensions in the codec in the entity inspector, then you manually create a subclass of NSManagedObject (again more often used to designate a class with the same name as Entity) it’s good to go, the reason you you need to have a class / extension of your entities, it is that it is much easier to deal with entity attributes as vars, and not "manually", like using a value (forKey: "") like Any ?, because when it comes to save dates using this technique, even if in "How" is the date or string, a bit Swift "allergy" to type "Any" because he is not much mentioned, so we avoid the use of "As many as possible"

0
source

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


All Articles