Here's what happened to me: I started following the NSPersistentDocument tutorial. In the section "Create the Data Model", it provides a link to "Creating a Managed Object Model using XCode", which I followed. There it has you create the Entities "Department" and "Employee" and assign their classes as "Department" and "Employee". It never mentions there that those classes must be defined in your project by creating a subclass of NSManagedObject. Don't you think it should mention that?
Having read that, I went back to the NSPersistentDocument tutorial and followed the steps for "Create the Data Model", except I (wrongly) changed the class of "Department" and "Employee" to "Department" and "Employee". The tutorial does not say to do this, but I did it because that was the procedure in "Creating a Managed Object Model using XCode". This prevented the example from working when I got to "Build and Test".
Later on in the tutorial, as you point out, it does direct the reader on how to create a custom Employee class, but that is irrelevant to the problem I point out. If you still think I'm obnoxiously wrong on all counts in my message, I'm sorry. I don't mean to knock Apple documentation, I am a great admirer of it. Apple's documentation is some the finest technical writing I have ever read in my life. I am just explaining my experience, and trying to correct what I think is wrong.
On Jun 13, 2005, at 1:17 AM, mmalcolm crawford wrote:
On Jun 13, 2005, at 12:53 AM, Larry Gerndt wrote:
In the "Data Modeling Guide", the article "Creating a Managed Object Model Using XCode" has a serious flaw. In its example, It directs you to change the Class of the Employee and Department entities from their default class (NSManagedObject) to class Employee and class Department, respectively. This will make them unusable. The class of a managed object must be a kind of NSManagedObject.
This is simply untrue. Please do not make this sort of assertion without checking your facts first.
The documentation clearly states that the class of a managed object must be NSManagedObject, *or a subclass thereof*.
"Managed objects must be instances of either NSManagedObject or a subclass of NSManagedObject."
Regarding the tutorial, it is made clear what effect the steps you take have on your class specifications:
"You have now defined two entities—Employee and Department—***and importantly you have specified that in your application these entities are represented by the Employee and Department classes respectively.***"
This bit me because having read this first, I then went to build and run the example "Introduction to NSPersistentDocument Core Data Tutorial" and while it doesn't say to do that there,
On the contrary:
This section makes it clear that in order to use a custom subclass of NSManagedObject (in this case 'Employee'), you must specify that subclass in the model:
"In the data model (use the entity detail pane, or edit the name directly in the Class column in the entity browser), change the class name for the Employee entity from NSManagedObject to Employee."
...
it also doesn't show the tables where those things are defined, so I didn't know any better and followed my previous directions.
... Contrast the instructions earlier in the tutorial:
"Items of note and not covered in the tables: The class for both entities is NSManagedObject; neither entity is abstract."
At this stage there is no custom class. The application can be tested without such.)
As such, when I build and run, the "Add" button resulted in a "failed to create object" exception. This stumped me for about 20 minutes. A visit to Cocoa Builder revealed a lengthy dicussion about how the class of Entities MUST be a kind of NSManagedObeject, so i changed it to that, and now it works.
Did this error occur whilst you were following the tutorial? If so, at what stage, and had you omitted any steps previously?
mmalc
-- Larry Gerndt AIM Handle: SonOfTheSonOfMan Let the truth be told though the heavens fall -- James Garrison
|