Swift and Core Data hiccups

When we decided to add core data to a swift project, we thought, a simple drag and drop of the core data model file would do the job. After some time wondering why it did not work, we finally found out, that xcode did not compile the file correctly, creating only a mom-file and not the momd-file package. The fix was easy, of course. We only had to create a new core data model file using New->File->… and then to copy the content from the old to the new model, which then worked as expected.

The other surprise of that day came while trying to access the class that we had created using Editor->Create NSManagedObject Subclass. We could not correctly use the subclass as we had done it using Objective-C. Again, after some minutes I remembered, what I had read in the iBook “Using Swift with Cocoa and Objective-C”, that since Swift has no flat class model, we needed to include the class name into the Class-Field of our Entity.

We did that by selecting the entity, opened the model entity inspector and prefixed our entity class with the project name separated by a dot. I just wonder if that class name ( e.g. project.entity ) would still be accessible using Objective-C as well. May be I’ll try that next time.