• 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: Another Core Data Ivar Setter and Undo Issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another Core Data Ivar Setter and Undo Issue


  • Subject: Re: Another Core Data Ivar Setter and Undo Issue
  • From: Felix Franz <email@hidden>
  • Date: Wed, 27 Jun 2007 12:28:14 +0200

Hi Ian,

I found a mail to this list from Kenny Leung very helpful: <http:// www.cocoabuilder.com/archive/message/cocoa/2006/9/2/170502> .

Basically in your setter-method you register a undo-operation to the ManagedObjectContext's UndoManager.
After CoreData undoes the change your undo-operation is called (which will simply
send the notification in your example).
For me the whole point of "getting undo for free" with CoreData is only true if you never put
any code in a NSManagedObject-subclass... (I would be happy to learn a better way, if anyone
has a better solution speak up! :) )


Cheers,

felix


On Jun 26, 2007, at 11:29 PM, Ian G. Gillespie wrote:

I've searched the archives and couldn't find and answer to my question, so here goes...

I have Core Data app where one entity say, "Department", wants to know when there is a change in one of its "Employee" entities (typical one-to-many relationship example). In the past I registered Department as an observer for changes in its Employees for the key paths of interest. This worked fine accept that it led to some performance issues when a Department was registering for changes in say 5000-10,000 Employees. To address this I wanted to use my know observing-notification system using NSNotificationCenter. I started implementing custom accessors in my Employee managed object sub-class so that I could post notifications (as seen below).

The problem is when I undo a change made on an Employee's property the setMyValue: method is not called again. It is only called when the user actually changes a value via bindings on the UI. I was hoping that when Core Data invokes undo that it would call the appropriate setter value for the property that changed. Is this the expected behavior of Core Data?

-(void)setMyValue:(NSNumber *)sumValue {

	[self willChangeValueForKey:@"myValue"];
	[self setPrimitiveValue:sumValue forKey:@"myValue"];
	[self didChangeValueForKey:@"myValue"];

//post the notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"myValueDidChange" object:self userInfo:nil];


}




_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Another Core Data Ivar Setter and Undo Issue
      • From: "Ian G. Gillespie" <email@hidden>
References: 
 >Another Core Data Ivar Setter and Undo Issue (From: "Ian G. Gillespie" <email@hidden>)

  • Prev by Date: Re: how to perform boolean operation on NSBezierPath
  • Next by Date: Two NSRects adjacent/touching?
  • Previous by thread: Re: Another Core Data Ivar Setter and Undo Issue
  • Next by thread: Re: Another Core Data Ivar Setter and Undo Issue
  • Index(es):
    • Date
    • Thread