How to create classes after creating Core Data model in Xcode for iPhone

IphoneCore Data

Iphone Problem Overview


I have created my Model, Entities, Properties and Relationships in Xcode. How are the classes for my Entities created? Do I have to manually create them?

Iphone Solutions


Solution 1 - Iphone

You can do this without leaving Xcode at all (see end of answer for Xcode 4 instructions):

  • Open your data model so it's visible in the editor pane
  • Single click Classes folder in Group & Pane pane
  • Now single click anywhere in the diagram pane.
  • Press ⌘N to bring up this dialog:

alt text

  • Finish the wizard to genereate code for one or more classes. Note: you select the classes for which to generate on a later step in the wizard - not shown here.

I picked this up on page 143 of More iPhone 3 Development

Update 12/6/2010:

Alternatively, you can just select one or more of the entities in the entity list, as shown below: alt text

And then press ⌘N to bring up the New file dialog shown above. If you accept the default location using this alternative, the generated classes will be put under your .xcdatamodel. Drag them manually to classes (Ref: Stanford, Developing Apps for iOS: ep. 12. Core Data and Table Views).

Update 3/26/2011 (Xcode 4):

For Xcode 4, simply bring up the New file dialog (⌘N) and select NSManagedObject subclass from Core Data. The wizard will ask you for which enities it should create classes.

enter image description here

Solution 2 - Iphone

With Xcode 4.3+, you can just :

  • click on your model
  • click the Editor Menu
  • click Create NSManagedObject subclass
  • save the files where you want

And it's done !

Solution 3 - Iphone

You can also use mogenerator. It now includes Xmo’d which seamlessly integrates mogenerator into Xcode.

Solution 4 - Iphone

You can also try MotoSwift.

  • It is simple
  • Supports Stencil template language
  • Contains swift templates similar to XCode generates and mogenerator generates

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPicflightView Question on Stackoverflow
Solution 1 - IphoneMads MobækView Answer on Stackoverflow
Solution 2 - IphoneTitouan de BailleulView Answer on Stackoverflow
Solution 3 - IphonePaul ArdeleanuView Answer on Stackoverflow
Solution 4 - IphoneIgor PalagutaView Answer on Stackoverflow