• 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: Strategy for read only Templates with Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strategy for read only Templates with Core Data


  • Subject: Re: Strategy for read only Templates with Core Data
  • From: George Orthwein <email@hidden>
  • Date: Mon, 19 Jun 2006 01:55:26 -0400

<http://developer.apple.com/documentation/Cocoa/Reference/ CoreDataFramework/Classes/NSManagedObject_Class/Reference/ Reference.html#//apple_ref/occ/instm/NSManagedObject/setValue:forKey:>

Argh, right in front of me. Thanks for pointing that out.... hey wait, I'm actually overriding setValue:forKeyPATH:... would that make it ok? It's only setValue:forKey: that NSManagedObject has its own version of, with a warning.


A model object should not be tied to a controller in this way.

Good point. I should be looking for a way to intercept the change in the controller.


Any reason why I shouldn't then move this code into setValue:forKeyPath: in a subclass of NSArrayController? The diagram in "Bindings Message Flow" indicates that this would be the place to trap changes sent from the views.

My app allows the user to adjust a bunch of settings and save them as Templates. [...]
Anyway, what I'd like is that when any changes are made to a default template, a copy is made and changes are made to the copy instead.


Is there any reason why you cannot simply make a copy at the outset?

E.g. I have Red Template, White Template, Blue Template. I don't want to show a "Red Template Copy" until Red is modified.


Ideally, I could intercept the change before it happens. If I make a copy beforehand, I have to deal with not showing the copy. If I wait until it is modified, I can copy but have to somehow revert or restore the original.

I suppose it could work this way:
1) I have a popup to select the template. I'll detach this from the "selection" of the NSArrayController and handle it manually.
2) I'll actually always have selected a "Custom" template in the NSArrayController, so that any time an edit is made with the controls, it changes this "Custom" template rather than a preset that I don't want modified.
3) If the user chooses a preset template from the popup, I'll copy the values from the preset template to the "Custom" template so it looks like the preset is selected. If an edit is then made, I'll change the popup selection back to "Custom".


I probably didn't explain that very well, but the key will be detaching the popup from actually causing selection in the NSArrayController. Since the editing controls are bound to the selection, I'll just make sure the actual selection is never a preset template. That way they can't get modified.

So I guess, in a way, that's making a copy at the outset. :)

Having a single "Custom" setting along with the saved templates is probably the more common way of handling presets anyhow. (Rather than making a separate copy of each template when it is edited.)

Thanks,
George

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Strategy for read only Templates with Core Data (From: George Orthwein <email@hidden>)
 >Re: Strategy for read only Templates with Core Data (From: George Orthwein <email@hidden>)
 >Re: Strategy for read only Templates with Core Data (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: CoreData: Getting the last object of a relation
  • Next by Date: Re: CoreData: Getting the last object of a relation
  • Previous by thread: Re: Strategy for read only Templates with Core Data
  • Next by thread: Do ArrayControllers have access to all data?
  • Index(es):
    • Date
    • Thread