如何在 iPhone 的 Xcode 中创建 Core Data 模型后创建类 [英] How to create classes after creating Core Data model in Xcode for iPhone
问题描述
我已经在 Xcode 中创建了我的模型、实体、属性和关系.我的实体的类是如何创建的?我必须手动创建它们吗?
您可以在不离开 Xcode 的情况下完成此操作(请参阅 Xcode 4 说明的答案结尾):
- 打开您的数据模型,使其在编辑器窗格中可见
- 单击 Group & 中的 Classes 文件夹窗格窗格
- 现在单击图表窗格中的任意位置.
- 按 ⌘N 调出此对话框:
- 完成向导以生成一个或多个类的代码.注意:您可以在向导的后续步骤中选择要为其生成的类 - 此处未显示.
我在 ).
2011 年 3 月 26 日更新(Xcode 4):
对于 Xcode 4,只需打开 New file 对话框 (⌘N) 并从 Core Data 中选择 NSManagedObject 子类.向导会询问您应该为哪些实体创建类.
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?
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:
- 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:
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.
这篇关于如何在 iPhone 的 Xcode 中创建 Core Data 模型后创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!