• 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: mmalcolm crawford <email@hidden>
  • Date: Sat, 17 Jun 2006 21:25:38 -0700


On Jun 5, 2006, at 11:35 AM, George Orthwein wrote:

I decided to intercept the changes by overriding setValue:ForKeyPath: in my NSManagedObject subclass and it seems to be working well. If the object is a "template" then I make a copy of it and make changes on the copy instead.

This is not code that belongs in the model object...

I thought I had read before that overriding setValue:ForKeyPath: is generally a bad idea. However, after searching for 45 minutes I'm not seeing where I read that, I'm only seeing a warning about efficiency in the docs. Anyway, I'm not re-implementing it... I'm just calling the super version.
Still, could calling the super version cause problems?


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

Here's my code:
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
// if default is yes then this is a template we want to copy rather than modify
if ([[self valueForKey:@"default"] boolValue]==YES) {
// create new managed object - (probably should insert into moc directly, rather than this keypath silliness)
BackgroundImage *newBg = [[[NSApp delegate] valueForKeyPath:@"inspectorController.backgroundController"] newObject];


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

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?

mmalc

_______________________________________________
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


  • Follow-Ups:
    • Re: Strategy for read only Templates with Core Data
      • From: George Orthwein <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>)

  • Prev by Date: Re: Bindings + Trapping Changes
  • Next by Date: Re: Apple's Secret Desktop Sauce
  • Previous by thread: Re: Strategy for read only Templates with Core Data
  • Next by thread: Re: Strategy for read only Templates with Core Data
  • Index(es):
    • Date
    • Thread