I started wondering: Since 'department' is in fact a managed object and can be fetched, why does MyDocument need it as an instance variable?

Answer: It doesn't!  I eliminated the declaration

        NSManagedObject *department ;

and also I eliminated the -setDepartment: setter and all invocations of it. Build, run, and everything works just fine! Whenever - [MyDocument department] is invoked (which does not happen very often, only when a document is saved), it fetches it from its managed object context.

Possibly, the 'department' ivar was introduced for efficiency, to avoid fetches. That seems pretty silly in this case, since it only gets accessed when the document is saved, and only once. Or maybe Apple just put it in there to make me think real hard and teach me a lesson.

So, in addition to Quincey's explanations, my lessons are:

1. Filenames of data models are meaningless; if same name as a class, that is purely coincidental. No connection between the two.

2. Managed objects are supposed to be managed by Core Data. Whenever you see an instance variable declared as a class based on NSManagedObject*, say "Huh" and ask "Why?"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to