gpt4 book ai didi

ios - '文件名用于区分同名的私有(private)声明'错误

转载 作者:IT王子 更新时间:2023-10-29 07:39:47 25 4
gpt4 key购买 nike

我在 Swift 中的 Xcode 8.1 中生成 NSManagedObject 时遇到此错误。

:0: error: filename "DemoOne+CoreDataClass.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataClass.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataClass.swift' :0: note: filenames are used to distinguish private declarations with the same name :0: error: filename "DemoOne+CoreDataProperties.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataProperties.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataProperties.swift' :0: note: filenames are used to distinguish private declarations with the same name Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

我搜索了这个并得到了答案,说该文件可能在项目中出现两次,但这不是我的情况。我遇到的另一个解决方案是从构建阶段删除文件并再次添加。那也没用。这是一些build设置配置错误吗?还是别的?

这是使用 Xcode 8.1 创建并显示此问题的演示项目的链接:- https://www.dropbox.com/s/xwyzhshktb2hqe7/demo2.zip?dl=0

最佳答案

出现此问题是因为 Xcode 自动子类生成 功能。

根据 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.


因此,为了解决您的问题,您需要将 Codegen 字段值设置为 Manual/None ,如下所示: Core Data Codegen

关于ios - '文件名用于区分同名的私有(private)声明'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40366329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com