2

OK, so I read that in Swift, we need to prefix our Core Data entity class names in the inspector with our project namespace.

Let's assume my project is called "MyProject", so for each on my Core Data entity in DataModel.xcdatamodeld I add "MyProject":

MyProject.Book
MyProject.Library

When I select the two entities in the Data Model interface builder and go

Editor > Create NSManagedObject Subclass

It only generated 1 class file called MyProject instead of the usual

Book class
Library class

That's how I normally do it with Objective C.

Is there an extra step with Swift that I'm not aware of ?

Zhang
  • 11,253
  • 6
  • 51
  • 80
  • Theres no step (provided by apple yet) unfortunately, but please tell me where you "read" about this. I have also been doing the same with XIBs i am just interested in a canonical reference:) – Daniel Galasko Jan 10 '15 at 07:13
  • @DanielGalasko I read it here http://stackoverflow.com/questions/25076276/unabled-to-find-specific-subclass-of-nsmanagedobject and Apple's documentation link: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WritingSwiftClassesWithObjective-CBehavior.html under section `Implementing Core Data Managed Object Subclasses` – Zhang Jan 10 '15 at 07:18

1 Answers1

2

Looks like a bug in Xcode that Apple needs to fix as mentioned in the comments of this Stackoverflow post by Martin R:

Unable to find specific subclass of NSManagedObject

A PITA work around

I was reading this

http://jamesonquave.com/blog/core-data-in-swift-tutorial-part-1/

It seems like the way to work around this for now is to:

  1. Before generating NSManagedObject subclass using using Editor, remove all the namespace prefix from entity class name

  2. Select all the entities you want to generate NSManagedObject subclass for and generate them using Editor

  3. Now add the namespace prefix back to all the entity class name and save the data model file.

Have to wait for Apple to fix it I guess =/

Community
  • 1
  • 1
Zhang
  • 11,253
  • 6
  • 51
  • 80