• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSPersistentDocument: "Settings" (DepartmentsAndEmployees) (From: Jerry Krinock <email@hidden>)
 >Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees) (From: Quincey Morris <email@hidden>)
 >Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees) (From: Jerry Krinock <email@hidden>)
 >Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees) (From: Quincey Morris <email@hidden>)
 >Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees) (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
  • Next by Date: Re: Creating Toolbar Items in IB
  • Previous by thread: Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
  • Next by thread: Creating icons and other resources
  • Index(es):
    • Date
    • Thread