• 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, 5 Jun 2006 14:35:18 -0400

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.

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?

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];


// copy the default's attributes
NSMutableDictionary *attributes = [[self dictionaryWithValuesForKeys:[[self entity] attributeKeys]] mutableCopy];


// mark it as NOT a default template
[attributes setValue:[NSNumber numberWithBool:NO] forKeyPath:@"default"];


// set name to be +" copy"
[attributes setValue:[NSString stringWithFormat:@"%@ copy",[self valueForKey:@"name"]] forKeyPath:@"name"];


		// copy attributes to newBg
		[newBg setValuesForKeysWithDictionary:attributes];

// select newBg
[[[NSDocumentController sharedDocumentController] currentDocument] setValue:newBg
forKeyPath:@"docPrefsController.selection.bgImage"];


		// finally, make the requested change on the copy
		[newBg setValue:value forKeyPath:keyPath];
	} else {
		[super setValue:value forKeyPath:keyPath];
	}
}
_______________________________________________
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: mmalcolm crawford <email@hidden>
    • 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>)

  • Prev by Date: Re: nsslider subclass not responding to mouseUp:
  • Next by Date: Modal dialogs and system edit menu items
  • Previous by thread: Strategy for read only Templates with Core Data
  • Next by thread: Re: Strategy for read only Templates with Core Data
  • Index(es):
    • Date
    • Thread