Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclassing NSManagedObject with swift 3 and Xcode 8 beta

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?

Thanks

like image 915
RFG Avatar asked Jun 19 '16 08:06

RFG


1 Answers

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.

From the 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.

like image 52
vadian Avatar answered Oct 20 '22 23:10

vadian