使用 swift 3 和 Xcode 8 beta 子类化 NSManagedObject [英] Subclassing NSManagedObject with swift 3 and Xcode 8 beta

查看:19
本文介绍了使用 swift 3 和 Xcode 8 beta 子类化 NSManagedObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始尝试在 swift 3 和 Xcode 8 beta 中使用 Core data.当我尝试从核心数据模型生成 NSManagedObject 子类并在编辑器菜单中创建 NSManagedObject 子类...选项时,Xcode 8 beta 生成三个文件,其中一个是 _COREDATA_DATAMODELNAME_+CoreDataModel.swift ,内容如下:

I've began to try use Core data with swift 3 and Xcode 8 beta. When I try to generate NSManagedObject subclasses from core data model and Create NSManagedObject subclass… option in Editor menu, Xcode 8 beta generates three files one of them is _COREDATA_DATAMODELNAME_+CoreDataModel.swift with the following content:

import Foundation
import CoreData

___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___

另外,这个文件的内容显示了两个警告:

In addition, the content of this file shows two warnings:

Expressions are not allowed at the top level.
Use of unresolved identifier '___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___'

有人遇到过同样的问题吗?这个新文件是什么意思?

Has anyones faced the same issue? Which is the meaning of this new file?

谢谢

推荐答案

这可能是与新的自动子类生成的(测试版)冲突,可以在数据模型文件的实体检查器中进行控制.

It's probably a (beta) clash with the new automatic subclass generation, which can be controlled in the entity inspector of the data model file.

来自文档(核心数据中的新功能)

Xcode 现在支持自动生成 NSManagedObject 子类在建模工具中.在实体检查器中:

Xcode automatic subclass generation

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

  • Manual/None 是默认的和以前的行为;在这种情况下你应该实现您自己的子类或使用 NSManagedObject.
  • Category/Extension 在名为 like 的文件中生成类扩展名ClassName+CoreDataGeneratedProperties.您需要声明/实施主类(如​​果在 Obj-C 中,扩展可以通过头文件导入名为 ClassName.h).-
  • 类定义生成名为像 ClassName+CoreDataClass 以及为类别/扩展.
  • 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.

生成的文件放在 DerivedData 和保存模型后,在第一次构建时重建.他们也是由 Xcode 编入索引,因此在引用上单击命令并快速打开按文件名有效.

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.

这篇关于使用 swift 3 和 Xcode 8 beta 子类化 NSManagedObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆