Duplicate files in DerivedData folder using CoreData generator

后端 未结 7 1841
庸人自扰
庸人自扰 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 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.

提交回复
热议问题