Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
- Subject: Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
- From: Jerry Krinock <email@hidden>
- Date: Sat, 25 Oct 2008 19:42:36 -0700
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 (email@hidden)
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:
This email sent to email@hidden