Master data is the right way to subclass NSManagedObject in an objective-c Xcode 8 project

I was just starting to learn how to use Core Data today, and ran into a problem when I had to subclass from NSManagedObject in my objective-c project. I am following the Stanford class iOS 7 (I came from the Swift background and want to learn more about objective-c ) Stanford University iOS 7 Application Development: Lecture 13 - Basic Data and Table View Here's what I've done so far:

First

Create my CoreDataModel.xcdatamodeld file and configure my objects like this

enter image description here

Further

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

enter image description here

Four Swift files were created, including the empty header file MyProject-Bridging-Header.h .

enter image description here

I have many compiler errors: enter image description here

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

How do I set up the header file so that objective-c recognizes my Swift files, or is there a way to create an objective-c subclass file, such as a .m and .h file?

Re-allocation error may arise from code issue Generating an automatic Xcode subclass

My details were as follows: enter image description here

Any suggestion is appreciated.

+6
source share
2 answers

When you select your model in the project navigator, in the File Inspector you can choose the language in which the code will be generated:

Change the language of the generated model

+10
source

This Answer already describes how to create Swift files. Mine covers the other queries in question.

Xcode now supports the automatic generation of NSManagedObject subclasses in the modeling tool. The generated files are placed in DerivedData and rebuilt on the first build after saving the model. They are also indexed by Xcode, so pressing keys on links and quickly opening by file name works.

See Apple documentation for more details .

Solution for invalid NSManagedObject update:

For Xcode 8.1, before creating an NSManagedObject through the Editor, select Entity , go to the Data Model Inspector and under Codegen select Guide / No :

And then subclass NSManagedObject .

If you have already created a subclass of NSManagedObject , follow these steps:

  • Go to the current .xcdatamodeld , set all Entities Codegen to Guide / No.
  • Save the project, delete the derived data.
  • Clean and create a project.

It should work.

+6
source

Source: https://habr.com/ru/post/1012924/


All Articles