gpt4 book ai didi

ios - 是否没有必要在 Swift 3 中子类化 NSManagedObject?

转载 作者:行者123 更新时间:2023-11-28 16:05:29 24 4
gpt4 key购买 nike

我以前知道您必须“编辑器”>“创建 NSManagedObject 子类”才能在您的类中引用核心数据的实体名称。但是,在创建这些自动子类后,我遇到了几个错误。

我的项目在没有这些子类文件的情况下运行良好,那么 Swift 3 是否不再需要子类来引用实体?

最佳答案

在 Swift 3 中,您不需要手动为 NSManagedObject 创建子类。

默认情况下,它们是自动创建的。但是,如果您想要手动创建文件,请在您的 testCD.xcdatamodeld 的实用程序区域中将 Codegen 设置为 Manual/None

来自 Apple 的 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 youshould implement your own subclass or use NSManagedObject.
  • Category/Extension generates a class extension in a file named likeClassName+CoreDataGeneratedProperties. You need to declare/implementthe main class (if in Obj-C, via a header the extension can importnamed 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.

关于ios - 是否没有必要在 Swift 3 中子类化 NSManagedObject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40374842/

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