Duplicate files in DerivedData folder using CoreData generator

后端 未结 7 1800
庸人自扰
庸人自扰 2020-12-28 13:29

I\'m trying to generate NSManagedModels from my datamodel. Generation works but after I got many errors :

error: filename \"Station+CoreDataProperties

相关标签:
7条回答
  • 2020-12-28 13:54

    I get this in Xcode 8.1 For me following steps solved the issue. Please note that order matters.

    1) Create entity in Core Data model.

    2) Under class section, make settings as on following image.

    Module: Current Product Name

    Codegen: Manual/None

    3) Generate your NSManagedObject subclass.

    0 讨论(0)
  • 2020-12-28 14:00

    After following the guidance from oyalhi and Vladimir Shutyuk, (deleting the NSManagedObject files, changing the entity codegen to Manual/None), I had to restart Xcode to allow it to index again before I could re-generate the NSManagedObject files and get a successful compile.

    0 讨论(0)
  • 2020-12-28 14:02

    If you generated CoreData subclasses with codegen: ClassDefinition your basically screwed. The only way to fix it is to:

    1. Delete your CoreData subclasses.
    2. Delete your derived data folder.
    3. Clean your project (CMD+K).
    4. Generate new CoreData subclasses, this time select Codegen: Manual/None and Module: Current Product Module
    0 讨论(0)
  • 2020-12-28 14:11

    This is not a bug. Codegen generates these files in the DerivedData folder, so you don't need to create them again in your project, hence the compile error.

    From Xcode 8.0 Release notes:

    Xcode automatically generates classes or class extensions for the entities and properties in a Core Data data model. Automatic code generation is enabled and disabled on an entity by entity basis, and is enabled for all entities in new models that use the Xcode 8 file format. This feature is available for any data model that has been upgraded to the Xcode 8 format. You specify whether Xcode generates Swift or Objective-C code for a data model using the data model’s file inspector.

    When automatic code generation is enabled for an entity, Xcode creates either a class or class extension for the entity as specified in the entity's inspector: the specified class name is used and the sources are placed in the project’s Derived Data. For both Swift and Objective-C, these classes are directly usable from the project’s code. For Objective-C, an additional header file is created for all generated entities in your model. The header file name conforms to the naming convention “DataModelName+CoreDataModel.h”.

    However, if you selected Category/Extension under the codegen pulldown menu in the data model inspector (because you want to add logic to your model): codegen will wrongly generate both the class definition and properties extension.

    The solution is to simply delete the properties extension (ClassName+CoreDataProperties.swift). Your project should now compile.

    0 讨论(0)
  • 2020-12-28 14:13

    This is indeed not a bug. As @Morrowless suggests both class definition and properties extension are created. If this is not wanted, select Manual/None under Codegen before generating the code. If the code is already generated, just delete them, and try Editor->Create NSManagedObject Subclass... again from the menu (after setting Manual/None).

    Note, in the picture below, the Class Name 'Contact' is specific to my project. You will see your entity name instead.

    0 讨论(0)
  • 2020-12-28 14:14

    For the sake of completeness..:

    I just ran into the same error, but none of the proposed solutions worked. What puzzled me was that even switching from automated code generation to manual for the one (as I thought) problematic entity didn't do anything.

    Finally, I figured out that I had several entities with the same name, but they all shared the same classname. The reason for this was that I copy&pasted one entity several times to save me some work, because they also have a few attributes in common.

    Turns out XCode renames the duplicates by adding 1, 2,... to the entity name, but leaves the class name as before. And since now entity name and class name are "unrelated", renaming the entity won't change the class name either.

    Hope it helps someone - I have also filed a bug report for this.

    0 讨论(0)
提交回复
热议问题