Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 4 Generating classes from entities in CoreData

Im using XCode 4 and working with CoreData. Now, how do I generate classes for entities? I used to do it in XCode 3 by clicking on a diagram entity, going to File->New and choosing NSManagedObject class.

For some reason i cant seem to find it in XCode 4, it's not showing up in the dialog...

like image 418
Doz Avatar asked Oct 31 '10 03:10

Doz


People also ask

How do I create a subclass in NSManagedObject?

From the Xcode menu bar, choose Editor > Create NSManagedObject Subclass. Select your data model, then the appropriate entity, and choose where to save the files. Xcode places both a class and a properties file into your project.

What is codegen in Core Data?

The Codegen menu is where you specify the code generation for the entity. There are three code generation options. Choosing Manual/None tells Xcode not to generate code for the entity. You must create the class for the entity by creating a new file or by choosing Editor > Create NSManagedObject Subclass.

How do I get data from Core Data?

Fetching Data From CoreData We have created a function fetch() whose return type is array of College(Entity). For fetching the data we just write context. fetch and pass fetchRequest that will generate an exception so we handle it by writing try catch, so we fetched our all the data from CoreData.

What is entity in Core Data?

An entity description describes an entity (which you can think of as a table in a database) in terms of its name, the name of the class used to represent the entity in your application, and what properties (attributes and relationships) it has.


4 Answers

Add NSManagedObject Subclass

If you are new to Xcode (like me) some graphics to make it easier to explain. Just make sure that you select the entities that you want before you click on "Create NSManagedObject Subclasss"

like image 59
DariusLau Avatar answered Oct 04 '22 19:10

DariusLau


You'll find in DP5 it is now a menu item. Finally!

like image 44
Adam Eberbach Avatar answered Oct 04 '22 19:10

Adam Eberbach


I got it working by making the entity CLASS the same as the entity NAME, i.e. "Person" instead of "NSManagedObject". I also noticed that I have to invoke File > New File twice (!) The first time, the Managed Object Class template is not available, but the second time it is. No clue why. I'm running XCode 3.2.4.

like image 45
Rayfleck Avatar answered Oct 04 '22 18:10

Rayfleck


While editing your xcdatamodel you need to select the entity and make sure the right hand Utilities pane is open. Select the Data Model Inspector (the tab on the right) and you can set the class of your entity to whatever you want.

like image 21
jj0b Avatar answered Oct 04 '22 18:10

jj0b