核心数据 – 使用swift 3和Xcode 8 beta对NSManagedObject进行子类化

前端之家收集整理的这篇文章主要介绍了核心数据 – 使用swift 3和Xcode 8 beta对NSManagedObject进行子类化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经开始尝试使用酷睿3和Xcode 8测试版的核心数据。当我尝试从核心数据模型生成NSManagedObject子类并在编辑器菜单中创建NSManagedObject子类…选项时,Xcode 8 beta生成三个文件,其中之一是_COREDATA_DATAMODELNAME_ CoreDataModel.swift,其内容如下:
import Foundation
import CoreData

___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___

此外,此文件内容显示两个警告:

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

有没有人面临同样的问题?这个新文件的意思是什么?

谢谢

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

documentation (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.

原文链接:https://www.f2er.com/swift/320409.html

猜你在找的Swift相关文章