'filenames are used to distinguish private declarations of the same name' error

前端 未结 8 576
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 00:40

I am getting this error on generating an NSManagedObject in Xcode 8.1 in Swift.

:0: error: filename \"DemoOne+CoreDataClass.swift\" used twice: \'/Us

相关标签:
8条回答
  • 2020-12-08 01:00

    The issue is happening because of the Xcode automatic subclass generation feature.

    According to What's New In Core Data

    Xcode automatic subclass generation

    Xcode now supports automatic generation of NSManagedObject subclasses in the modeling tool. In the entity inspector:

    • Manual/None is the default, and previous behavior; in this case you should implement your own subclass or use NSManagedObject.
    • Category/Extension generates a class extension in a file named like ClassName+CoreDataGeneratedProperties. You need to declare/implement the main class (if in Obj-C, via a header the extension can import named ClassName.h).
    • Class Definition generates subclass files named like ClassName+CoreDataClass as well as the files generated for Category/Extension.

    The generated files are placed in DerivedData and rebuilt on the first build after the model is saved. They are also indexed by Xcode, so command-clicking on references and fast-opening by filename works.


    So for fixing your issue, you need to set the Codegen field value to Manual/None as shown below:

    0 讨论(0)
  • 2020-12-08 01:07

    This is what I did to fix this issue,

    1. Select your entity in the data model
    2. Set the Module to Current Product Module
    3. Leave the Codegen to Class Definition though Manual/None also works
    4. Select Editor > Create NSManagedObject Subclass
    0 讨论(0)
提交回复
热议问题