将NSManagedObject子类化为swift 3和Xcode 8 beta [英] Subclassing NSManagedObject with swift 3 and Xcode 8 beta
问题描述
我开始尝试使用Core data with swift 3和Xcode 8 beta。当我尝试从核心数据模型生成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?
感谢
推荐答案
它可能是一个(beta)与新的自动子类生成冲突,可以在数据模型文件的实体检查器中控制。
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:
- 手动/无在这种情况下,你
应该实现你自己的子类或使用NSManagedObject
。 - 类别/ >在名为
ClassName + CoreDataGeneratedProperties
的文件中生成类扩展。你需要声明/ implement
主类(如果在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.
这篇关于将NSManagedObject子类化为swift 3和Xcode 8 beta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!