Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data - The correct way to subclass NSManagedObject in objective-c project Xcode 8

I just get started learning how to use Core Data today and encountered an issue when I have to subclass from NSManagedObjectin my objective-c project. I'm following the Stanford iOS 7 class(I come from Swift background and want to learn more about objective-c) Stanford University Developing iOS 7 Apps: Lecture 13 - Core Data and Table View Here is what I've done so far:

First

Create my CoreDataModel.xcdatamodeld file, and configure my entities like this

enter image description here

Next

With the CoreDataModel.xcdatamodeld file highlighted, I go to the Editor and try to create NSManagedObject subclass

enter image description here

Four Swift files were created inclduing an empty bridging header file MyProject-Bridging-Header.h.

enter image description here

I have a many compiler errors: enter image description here

I'm confused about why the xcode will generate Swift files for me instead of objective-c one since I have already configured using objective-c as my language.

How can I configure my header file to make objective-c recognize my Swift files or is there a way to create objective-c subclass file instead, such as .m and .h file?

The redeclaration error may come from the the codegen issue Xcode automatic subclass generation

My drived data have the following files enter image description here

Any suggestion is appreciated.

like image 362
Kesong Xie Avatar asked Dec 06 '16 01:12

Kesong Xie


1 Answers

When you select your model in Project navigator, in File inspector you have an option to select the language in which code will be generated:

Changing language of generated model

like image 178
Łukasz Przytuła Avatar answered Sep 28 '22 05:09

Łukasz Przytuła